[thelist] [TIP] Regular Expression help

Daniel Fascia danfascia at totalise.co.uk
Wed Jun 19 09:24:00 CDT 2002


<tip type = "PHP/regexp" author = "danfascia">

>DF> Guys, Im trying to create a regular expression in PHP which will FIND and REPLACE
>DF> anything lying in between 2 tags Ive made..
>
>DF> <!-- #CMS:Title --> .....this gets replaced..... <!-- #CMS:Title /-->

If anyone was interested, the findings were:

 ereg_replace('<!-- #CMS:Title -->.*<!-- #CMS:Title /-->',$replacement, $target)
- was far too broad spectrum and did not work with multiple instances of a tag in a file

 ereg_replace('<!-- #CMS:Title -->[^>]+<!-- #CMS:Title /-->',$replacement, $target)

did the trick nicely since it looked for the first instance of a close tag terminator >

</tip>

<tip type = "wisdom" author = "danfascia">

*NEVER* try to write your own CMS, its a mission and a half and there are inevitably
better programs already out there!

</tip>






More information about the thelist mailing list