[thelist] Complicated PHP Search and Replace
danieleastwell at onetel.net.uk
danieleastwell at onetel.net.uk
Tue Nov 9 10:28:02 CST 2004
Hi,
This is my first time posting - I've been struggling with this
problem all day and haven't really come that close to
resolving it, I'm hoping you can all help.
I'm developing a rudimentary content management system that
tags up content with non-standard tags, for example,
<link> http://web address here <linktext> link text here </link>
for a link, and
<bullet>bullet items here</bullet>
for unordered lists.
I've worked out the simple str_replace for the <link> tags to
create working hyperlinks on pseudo tags pulled from the
database to the viewed HTML, but am struggling with the coding
of the unordered lists.
I have this psuedo-code so far, that operates on the content
after having converted the <bullet> tags to conventional
<ul><li> opening and closing tags (only at the beginning and
end of an unordered list):
go through $content and for every <ul>, find <li>, then,
until you find </li>, find \n and replace with </li>\n<li>
and have given it this structure:
for($i=0 ; $i == strlen($content); $i++){ // all of the content
for( ; ;){ // every <ul>
if(){ // there is a <li>
for( ;;){ // until there is a </li>
$content = str_replace("\n",
"</li>\n<li>", $content);
}
}
}
}
The problem comes with the coding. The iteration over the
content does not seem to work, and I can't get my head round
the correct way of thinking in order to operate a string
function on a substring, only from a particular starting
point/needle.
Any advice would be gratefully received.
Regards,
Dan Eastwell.
More information about the thelist
mailing list