javascript - Parameter encoding (quotes and space character) -


so i'm sending string parameter javascript function, , problem space characters and/or quotes. can have either 1 working, can't figure out how both ways work @ same time.

i left encodeuricomponent , decodeuricomponent example use them deal spaces.

javascript:

function alerttitle(title){     alert(decodeuricomponent(title)); } 

php:

//...fetching mysql $title = $row['title'];  //if $title content wrapped in single or double quotes, do: $title = str_replace("\"","&quot;",$row['title']); //but if it's not, , has spaces, have wrap in quotes encodeuricomponent: $title = '\''.$row['title'].'\'';  //and gives error in encodeuricomponent if $title happens have // single quotes  //..and sending $title javascript: echo '<a onclick="alerttitle(encodeuricomponent('.$title.'));" href="#">alert</a>'; 

so somehow need escape single quotes also, or come different approach. close, wish have missed simple.

$title might anykind of following examples:

"title"

"title spaces"

'title'

'title' "all combined"

title "blaablaa" here

and on.

all hints more welcome. thanks!

just add pre-replace using single quotes :)

//...fetching mysql $title = $row['title'];  //if $title content wrapped in single or double quotes, do: $title = str_replace("\"","&quot;",$row['title']); $title = str_replace("\'","&#39;",$row['title']);  //but if it's not, , has spaces, have wrap in quotes encodeuricomponent: $title = '\''.$row['title'].'\'';  //and gives error in encodeuricomponent if $title happens have // single quotes  //..and sending $title javascript: echo '<a onclick="alerttitle(encodeuricomponent('.$title.'));" href="#">alert</a>'; 

Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -