arrays - PHP - str_replace(); -


i'm entering news on website through form. while adding news or editing it, \r or \n replaced br.

now still have issue, when write example "i've" print out i\'ve.

first question, caused due mysql_real_escape_string(); ? second question, how can replace multiple matches diffirent tags ?

right have this:

$order = array("'", "\'"); $replace = "&acute;"; $order = array("\r\n", "\n", "\r"); $replace = "<br />"; $string = $news; $insert = str_replace($order, $replace, $string); 

i'm sure not correct way because assigned same variables,.. point me in right direction please ?

edit: although works, 'allowed' code ?

edit: thank answers, problem fixed ! :)

yes, not right way it.

you should start ensuring using consistent character set in html , in database. next, remember magic rule: never sanitize input, sanitize output.

i.e. change data put database should mysql_real_escape_string() (or use bound parameters). output browser, use htmlentities() - not attempt write own versions of these. not use stripslahses unless there no appropriate method of escaping content corectly.

also, make sure addslashes disabled everywhere in php.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -