0
$item->description = preg_replace("/\<center\>\<a href=\"(.*)\"\>\<img alt=\"\" src=\"(.*)\" \/\>\<\/a\>\<\/center\>/", "$2", $item->description); 

But I need to put result $2 into string $item->image.
How to do it?

1 Answer 1

1

Try with:

$item->image = preg_replace("/.*\<center\>\<a href=\"(.*)\"\>\<img alt=\"\" src=\"(.*)\" \/\>\<\/a\>\<\/center\>.*/", "$2", str_replace("\n", '', $item->description)); 

How ever do not use regex for parsing html use instead DOM instead

Sign up to request clarification or add additional context in comments.

6 Comments

No, Then $item->image will be with all content, which have $item->description.
No, I need to parse XML and $item->description have html code and I want to clear it. Btw, this script will work on time per hour.
So your $item->image how should be? You said that $2 should be assigned to $item->image.
Yes, I need only $2, but not all $item->description.
I've updated my answer. Try now. I've added .* at the beginning and at the end of regex.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.