Jump to content


Photo

str functions


  • Please log in to reply
2 replies to this topic

#1 supanoob

supanoob
  • Members
  • PipPipPip
  • Advanced Member
  • 342 posts

Posted 24 July 2006 - 07:34 PM

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:

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

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

#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,017 posts

Posted 24 July 2006 - 07:40 PM

str_replace (array('[b]', '[/b]'), array('<b>', '</b>'), $topbody)

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#3 effigy

effigy
  • Staff Alumni
  • Advanced Member
  • 3,600 posts
  • LocationIL

Posted 24 July 2006 - 07:43 PM

...or regex:

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

Regexp | Unicode Article | Letter Database
/\A(e)?((1)?ff(?:(?:ig)?y)?|f(?:ig)?)\z/




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users