You are here: Re: eregi and eregi replace « PHP Programming Language « IT news, forums, messages
Re: eregi and eregi replace

Posted by Jim Michaels on 02/15/06 00:22

"Jim Michaels" <jmichae3@nospam.yahoo.com> wrote in message
news:27-dnTtIL5L0NXTenZ2dnUVZ_vmdnZ2d@comcast.com...
>
> "John Dunlop" <usenet+2004@john.dunlop.name> wrote in message
> news:1137011110.230535.227620@g49g2000cwa.googlegroups.com...
>> Nel wrote:
>>
>>> <?PHP
>>> $htmlsource = '<img src="pics/hotdog.gif"> text text <img
>>> src="pics/silly%20sausage.gif"> ';
>>> eregi('(=")(pics/)([0-9a-zA-Z%/ ]+.[a-zA-z]..)(")',$htmlsource,$imagesintext);
>
> Be aware that . matches any character: escape it with a \ if you want a
> dot.
> Also, the range A-z includes [\]^_` along the way. were you trying for
> this?
> eregi('(=")(pics/)([0-9a-zA-Z_\-%/ ]+\.[jpgifpnJPGIFPN]{3})(")',$htmlsource,$imagesintext);

can be further shortened:
eregi('(=")(pics/)([\d\w_\-%/ ]+\.[jpgifpnJPGIFPN]{3})(")',$htmlsource,$imagesintext);


> BTW, you should not allow spaces (%20) in filenames on a web site.
>
>>> ?>
>>
>> [...]
>>
>>> What I am trying to do is replace all images in the format
>>> ="pics/image.jpg"
>>> with "image.jpg" and at the same time make a list of the files
>>> image.jpg.
>>> The problem is how to pick up ALL the occurances, not just the first???
>>
>> preg_match_all(). preg_match is described as an alternative to ereg()
>> and it stops searching after finding one match, so I assume ereg()
>> stops then too.
>
>
> Try to tinker with preg_grep?
>
>
>>
>> http://www.php.net/manual/en/function.preg-match-all.php
>>
>>> Also how to use replace to remove the pics/ bit of the string.
>>
>> Replace them with the zero string. preg_replace().
>>
>> http://www.php.net/manual/en/function.preg-replace.php
>>
>> --
>> Jock
>>
>
>

 

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

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