preg_replace() isn't working like I think it should ^^;
Posted: Sat Mar 12, 2005 5:35 pm
Here's the text file:
Code: Select all
<ul>
<li>test</li>
</ul>
<br /><i><b>test</b></i>
<br />
<br /><div class="e;code"e;><b>test</b>
<br /><i>test</i>
<br /><b><i>test</i></b></div>Code: Select all
їlist]
ї*]testї/*]
ї/list]
їi]їb]testї/b]ї/i]
їcode]їb]testї/b]
їi]testї/i]
їb]їi]testї/i]ї/b]ї/code]Code: Select all
<ul>
<li>test</li>
</ul>
їi]їb]testї/b]ї/i]
їcode]їb]testї/b]
їi]testї/i]
їb]їi]testї/i]ї/b]ї/code]Code: Select all
<?php
function parsefrom($txt) {
$preg_good = array(
"[url=\\1]\\2[/url]",
"[img]\\1[/img]",
"[b]\\1[/b]",
"[u]\\1[/u]",
"[i]\\1[/i]",
"[s]\\1[/s]",
"Code: Select all
\\1"[color=\\1]\\2[/color]",
"[size=\\1]\\2[/size]",
"parselist_back('\\1');" // << what it should do afterwards
);
$smile_g = array(
":)",
":(",
";)",
":D",
":'(",
":P",
":-/",
"O_O"
);
$preg_bad = array(
"/<a href=\"(.+?)\" target=\"_blank\">(.+?)<\/a>/i",
"/<img src=\"(.+?)\">/i",
"/<b>(.+?)<\/b>/i",
"/<u>(.+?)<\/u>/i",
"/<i>(.+?)<\/i>/i",
"/<span style=\"text-decoration: line-through;\">(.+?)<\/span>/i",
"/<div class=\"code\">(.+?)<\/div>/i",
"/<span style=\"color: (.+?);\">(.+?)<\/span>/i",
"/<span style=\"font-size: (.+?)px;\">(.+?)<\/span>/i",
"/<ul>(.+?)<\/ul>/ie" // << line in question
);
$smile_b = array(
"/<img src=\"wiki\/smile.gif\" \/>/i",
"/<img src=\"wiki\/sad.gif\" \/>/i",
"/<img src=\"wiki\/wink.gif\" \/>/i",
"/<img src=\"wiki\/grin.gif\" \/>/i",
"/<img src=\"wiki\/cry.gif\" \/>/i",
"/<img src=\"wiki\/tongue.gif\" \/>/i",
"/<img src=\"wiki\/puzzled.gif\" \/>/i",
"/<img src=\"wiki\/confused.gif\" \/>/i"
);
$txt = preg_replace($preg_bad, $preg_good, $txt);
$txt = preg_replace($smile_b, $smile_g, $txt);
$bad = array('&', '<', '>', '"');
$good = array('&', '<', '>', "\"");
$txt = str_replace($bad, $good, $txt);
return str_replace('<br />', "\n", $txt);
}
function parselist_back($meh) {
$meh = "
- " . $meh . "
return preg_replace("/<li>(.*?)<\/li>/i", "[*]\\1[/*]", $meh);
}
It's got to be some small error I'm making, but I just can't see it.
Anyone know anything?