Jump to content

Archived

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

supanoob

str functions

Recommended Posts

well i have a function to change [ & ] to < & > but it doesnt seem to change the [/ & ] part at the end of the code. this is the function:

[code]function tml ($topbody) { $topbody=htmlspecialchars($topbody); $topbody=str_replace('[b]','<b>',$topbody); return nl2br($topbody); }
[/code]

and whenever i type [ b] it works but whenever i put [/ b] it doesnt :S

Share this post


Link to post
Share on other sites
[code]str_replace (array('[b]', '[/b]'), array('<b>', '</b>'), $topbody)[/code]

Share this post


Link to post
Share on other sites
...or regex:

[code]<?php
echo preg_replace('%\[(/?b)\]%', "<$1>", '[b]This[/b] is bold.');
?>
[/code]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.