-1

I have this string:

<h1>title</h1>

<p>hello world</p>

<img class="size-full wp-image-3824 alignright" src="https://alimentosysuplementos.com/wp-content/uploads/2017/07/Sándwich-con-queso-asado-arándanos-y-fresas..jpg" alt="Sándwich con queso asado, arándanos y fresas." width="360" height="450" />

I have to convert it to this:

title

hello world

https://alimentosysuplementos.com/wp-content/uploads/2017/07/Sándwich-con-queso-asado-arándanos-y-fresas..jpg

How to do it dynamically for several strings like this one???...

I'm working on an API to get the posts from a regular wordpress site and send it to a mobile app, because of that I have to remove all the HTML but keep the content.

I'm using Laravel 5.5 - PHP 7.1

Someone could help me pleaseee! :)

  • 4
    Possible duplicate of [Get img src with PHP](https://stackoverflow.com/questions/10130858/get-img-src-with-php) - don't regex because [H̸̡̪̯ͨ͊̽̅̾̎Ȩ̬̩̾͛ͪ̈́̀́͘ ̶̧̨̱̹̭̯ͧ̾ͬC̷̙̲̝͖ͭ̏ͥͮ͟Oͮ͏̮̪̝͍M̲̖͊̒ͪͩͬ̚̚͜Ȇ̴̟̟͙̞ͩ͌͝S̨̥̫͎̭ͯ̿̔̀ͅ](https://stackoverflow.com/a/1732454/3600709) – ctwheels Sep 26 '19 at 17:57

1 Answers1

0
$parsed = strip_tags(preg_replace('/<img\s+([a-z-\d]+="[^"]*"\s*)*src="([^"]+)"[^>]*>/si', '$2', $text));
Pavel Tzonkov
  • 264
  • 3
  • 9