note 59040 deleted from function.preg-replace by tularis
| From: | tularis@php.net | Date: | Sun, 18 Jun 2006 13:28:25 +0000 |
| Subject: | note 59040 deleted from function.preg-replace by tularis | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-114320@lists.php.net to get a copy of this message | ||
Note Submitter: mario at kuru dot cz
----
I'm using it for upload newsletter templates to server.
<?php
//Replace old path of images(gif || jpg || png) with $New_Path in $HTMLString
function Make_Replace_Image_Path($HTMLString, $New_Path) {
$new_path = "src=\"$New_Path\\3";
$pattern = '/(src=(\'|").*\/(.*(\.jpg|\.gif|\.png)))/';
$Result_String = preg_replace($pattern, $new_path, $HTMLString);
return($Result_String);
}
?>
Example:
<?php
$HTMLString = '<img alt="" src="/somewhere/something.jpg">';
$New_Path = 'http://www.kuru.cz/';
print Make_Replace_Image_Path($HTMLString, $New_Path)
?>
will return
<img alt="" src="http://www.kuru.cz/something.jpg">