You are here: Re: [PHP] String replace inside <img> « PHP « IT news, forums, messages
Re: [PHP] String replace inside <img>

Posted by Jason Wong on 01/07/05 15:03

On Friday 07 January 2005 07:32, Fredrik Arild Takle wrote:
> I have a some problems doing a search and replace in a string.
> I want to replace:
> <img ALT="" src="base/image.php?id=3" border=0>
> with
> <img ALT="" src="image.php?id=3" border=0>
>
> Note ALT, src, border properties may come in random order.
>
> My solution today is a not good enough because I only do an eregi_replace
> on all image.php, I only want to replace those inside a <img>
>
> Todays solution
> $string = eregi_replace("base\/image.php", "image.php", $string);
>
> Solution?

The quick and dirty solution would be to

str_replace('src="base/image.php', 'src="image.php', ...)

based on the assumption that 'src="base/image.php' only appears inside an
<img> tag.

Otherwise:

$doo = '<img ALT="" src="base/image.php?id=3" border=0>';
$dah = preg_replace('|(<img .*src=")(.*)(\?id=\d+" .*>)|ie',
'"$1".basename("$2")."$3"', $doo);
echo $dah, NL;

Season to taste.

--
Jason Wong -> Gremlins Associates -> www.gremlins.biz
Open Source Software Systems Integrators
* Web Design & Hosting * Internet & Intranet Applications Development *
------------------------------------------
Search the list archives before you post
http://marc.theaimsgroup.com/?l=php-general
------------------------------------------
New Year Resolution: Ignore top posted posts

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация