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("\"",""",$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("\"",""",$row['title']); $title = str_replace("\'","'",$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
Post a Comment