Jump to content

preg_replace help


Arceus

Recommended Posts

$message=mysql_result($posts,$ppp,"message");$username=mysql_result($posts,$ppp,"username");$puid=mysql_result($posts,$ppp,"uid");$profpic=mysql_result($posts,$ppp,'avatar');$sig=mysql_result($posts,$ppp,'signature');$sig=preg_replace("#\s*<base[^>]*>\s*#is", "", $sig);$avatar=mysql_result($posts,$ppp,'avatar');$avatar=preg_replace("dateline=(.*?)", "", $avatar); $sig=preg_replace(“[b](.*?)[/b]”, “<strong>$1</strong>”, $sig); /*line it doesn't like*/$sig=preg_replace(“[i](.*?)[/i]”, “<i>$1</i>” ,$sig);$sig=preg_replace(“[url="http://(*.?)"](*.?)[/url]”, “<a href=’$1’>$2</a>”, $sig);$sig=preg_replace(“[url="http://(.*?)"](.*?)[/url]”, “<a href=’$1’>”, $sig);$sig=preg_replace(“[color="#"](.*?)[/color]”, “<div style=’color:$1’>$2</div>”, $sig);$sig=preg_replace(“<!--coloro:--><span style="color:"><!--/coloro-->(.*?)[/color]”, “<div style=’color:$1’>$2</div>”, $sig);

Link to comment
Share on other sites

What you've posted uses curly quotes instead of normal quotes. PHP does not recognize curly quotes as string delimiters. Perhaps it is no coincidence that the problem line is the first line to use curly quotes. (It could also be a copy/paste problem that doesn't really exist in your code. I don't know.)

Link to comment
Share on other sites

Apparantly that's what I get for trying to write it all on MS Word then copy pasting. /me would like it if the next version of PHP will allow curly quotes.

Link to comment
Share on other sites

It's never going to allow curly quotes, those characters are just some high-numbered UTF characters which happen to look like quotes in the character set you're using. PHP and other programming languages only recognize ASCII quote characters as quotes.

Link to comment
Share on other sites

Here is a bigger picture :

$query="SELECT * FROM mybb_sgposts WHERE conid='$conid'";mysql_query($query);$posts=mysql_query($query);$postcount=mysql_numrows($posts);$ppp=0;echo "<table border='1'>";while ($ppp<$postcount){$message=mysql_result($posts,$ppp,"message");$username=mysql_result($posts,$ppp,"username");$puid=mysql_result($posts,$ppp,"uid");$profpic=mysql_result($posts,$ppp,'avatar');$sig=mysql_result($posts,$ppp,'signature');$sig=preg_replace("#\s*<base[^>]*>\s*#is", "", $sig);$avatar=mysql_result($posts,$ppp,'avatar');$avatar=preg_replace("dateline=(.*?)", "", $avatar);$sig=preg_replace("[b](.*?)[\b]", "<strong>$1</strong>", $sig);$sig=preg_replace("[i](.*?)[/i]", "<i>$1</i>" ,$sig);$sig=preg_replace("[url=(*.?)](*.?)[/url]", "<a href='$1'>$2</a>", $sig);$sig=preg_replace("[url](.*?)[/url]", "<a href='$1'>", $sig);$sig=preg_replace("[color=#(.*?)](.*?)[/color]", "<div style='color:$1'>$2</div>", $sig);$sig=preg_replace("[color=(.*?)](.*?)[/color]", "<div style='color:$1'>$2</div>", $sig);echo "<tr><td width='25%'><a href='/forums/member.php?action=profile&uid=$puid'>$username</a></td><td width='50%'>$message</td></tr>";echo "<tr><td><img src='$profpic' /></td><td>$sig</td></tr>";$ppp++;}echo "</table>";

Now the problem is it won't display $sig at all. I made sure in the database it says this for sig:

[b][color=green]CAM Webmaster.[/color][/b]

All other parts are displaying correctly.

Link to comment
Share on other sites

The code for url and color is where I am kind of confused on how to code it.

$sig=preg_replace("/\[url=\(*.?)\](*.?)\[\/url\]/is", "<a href='$1'>$2</a>", $sig);

Link to comment
Share on other sites

Apparantly that's what I get for trying to write it all on MS Word then copy pasting. /me would like it if the next version of PHP will allow curly quotes.
Although I wouldn't recommend using Word as an HTML editor (see my signature for some code editor links), I think "Smart Quotes" can be disabled.
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...