regex - php: preg_match and preg_replace -


i'm unsure of how following...

i need search through string , match instances of forward slash , certain letters. word modifications users have ability input , want them able modify individual words.

here example string

hello, isn't weather absolutely beautiful today!?

what i'd user able this

hello, isn't /bo weather /it beautiful today!?

take note of /bo , /it

what i'd have preg_match , or preg_replace statement finds , replaces instances of /bo , /it , converts them instead html tags such bolded html tag , italics html tag (i cant type them here or converted actual html. wrap around word following /bo in example wind being

hello, isn't <b>weather</b> <i>beautiful</i> today!? 

any ideas how regex?

once conversions done i'll standard sanitizing before inserting data database along prepared statements.

$string = "hello, isn't /bo weather /it beautiful /bo today!?";  var_dump(preg_replace (array('/\/bo\s(\w+)/', '/\/it\s(\w+)/'), array('<b>$1</b>', '<i>$1</i>'), $string)); 

"hello, isn't weather beautiful today!?"


Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -