John Davidson

arrays - Changing image links in text [PHP]


I want to replace the image links in the text with the following, but it doesn't. I'm sure everything is correct but I don't know what the problem is. Can you help me with this issue?

{#img='image_name.jpg', alt=''}

PHP code:

$text = "Hello <img src=''> , <img src=''> and now you :)";
$re = '/<img.*?src=[\'"]([^"\'])[\'"]>/';
preg_match_all($re, $text, $matches, PREG_SET_ORDER, 0);
foreach ($matches as $val) {
$str = preg_replace('/<img.*?src=[\'"](' . $val[1] . ')[\'"]>/', "{#img='" . $val[1] . "', alt=''}", $text);


Hello <img src=''> , <img src=''> and now you :)

My Answer:
Sure, I can help you with that. Can you please provide me with the code you are using to replace the image links in the text? This will help me better understand the issue and provide you with a solution.

Rate this post

4 of 5 based on 2729 votes


© 2024 - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us