Advertisement
Guest User

Untitled

a guest
Sep 19th, 2019
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. <?php
  2.  
  3.  
  4.  
  5. function replaceMoovitUrl($image_url) {
  6. // $full_url = "https://moovitapp.com/wp-content/uploads/2019/07/23153249/IMG_1376.jpg";
  7. $full_url = $image_url;
  8.  
  9. $old_url = substr($full_url, strpos($full_url, 'wp-content'));
  10.  
  11.  
  12.  
  13. $split = explode("/",$old_url);
  14. if (strlen($split[4]) > 6) {
  15. unset($split[4]);
  16. }
  17.  
  18. $new_url = implode("/",$split);
  19.  
  20. $new_full_url = str_replace($old_url, $new_url, $full_url);
  21. return $new_full_url;
  22. }
  23.  
  24.  
  25.  
  26.  
  27. $content = "<img src='https://moovitapp.com/wp-content/uploads/2019/07/23153249/IMG_1376.jpg'>";
  28.  
  29.  
  30.  
  31.  
  32.  
  33. $dom = new DOMDocument();
  34. $dom->loadHTML($content);
  35.  
  36. foreach ($dom->getElementsByTagName('img') as $img) {
  37. $img_src = $img->getAttribute('src');
  38. $img_new_src = replaceMoovitUrl($img_src);
  39.  
  40. $img->setAttribute('src', $img_new_src);
  41. }
  42.  
  43. $content = $dom->saveHTML();
  44.  
  45.  
  46. echo $content;
  47.  
  48.  
  49.  
  50.  
  51. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement