Forum Moderators: coopster
I am trying to figure out how to use php to convert a string (a url) into html entities
Example:
http://ww 19;.ebookwho lesaler.n et/r/g.ph 12;?u=trimak mini
(broken up with spaces so that it will wrap in the window...)
I've tried a couple of functions, but they don't seem to yield the result I am looking for - they just produce codes for "special characters" - where I want the codes for all characters (including .,:,/,?)
Any ideas?
Thanks!
$data = 'http://www.yahoo.com/?q=';
$url = urlencode(serialize($data));
echo $url;
Produced:
s%3A24%3A%22http%3A%2F%2Fwww.yahoo.com%2F%3Fq%3D%22%3B
http and www.yahoo.com were not encoded. I want the whole string to come out the other end encode in html entities.... Ideas?
it is this
// speeds things up
d = document;
// our regexp for evaluating email addresses
var pattern = /^[a-zA-Z0-9\-\._]+@[a-zA-Z0-9\-_]+(\.?[a-zA-Z0-9\-_]*)\.[a-zA-Z]{2,8}$/;
function init()
{
// get form objects
ascObj = d.getElementById("ascii");
uniObj = d.getElementById("unicode");
}
function obf() {
// get string (convert to lowercase)
s = ascObj.value.toLowerCase();
// find length of string
strLen = s.length;
// validate the email
noErrs = true;
if(strLen == 0) {
alert("You appear to have left the email address field blank. What's up with that?");
noErrs = false;
} else {
if(!pattern.test(s)) {
if (!confirm("Your entry, \""+s+"\", "+" does not appear to be a valid email address. Continue?")) {
noErrs = false;
}
}
}
// if it's a valid address, or they want to convert it anyway, then proceed
if (noErrs) {
// clear value of new string
newStr = "";
// loop through characters from last to first
for (i=strLen-1;i>-1;i--)
{
// build new string
newStr = "&#" + s.charCodeAt(i) + ";" + newStr;
}
// insert value for new email address
uniObj.value = newStr;
}
}
</script>
that'll work but you need to convert it to php ;)