coops Posted October 5, 2007 Share Posted October 5, 2007 HI, I'm doing a simple function retrieve data and export the data into xml, but found out xml does not like all character. The character I have found are '&','','<','>','£'. So I have developed a simple function that will replace curtain character within a string with the HTML code that XML likes. '&','¬','<','>','£' It seems to work with all character, but apart from "£" sign. The only reason is because if i use the below code while($i < strlen($value)){ $ia=0; $sign = $value{$i}; while($ia < count($strarValidation)){ if($strarValidation[$ia] == $sign){ $sign = $strarNewChar[$ia]; break; } $ia++; } $endValue.= $sign; The value at $sign = $value{$i}; for a £ is the HTML code, not "£". So the function can't be used... Does anyone else know of a way that I can stop the "£" converting to the html code when converting the string variable into a array? Thanks Link to comment https://forums.phpfreaks.com/topic/71953-%C2%A3-in-a-variable/ Share on other sites More sharing options...
Yesideez Posted October 5, 2007 Share Posted October 5, 2007 £ Use that in the HTML. Link to comment https://forums.phpfreaks.com/topic/71953-%C2%A3-in-a-variable/#findComment-362393 Share on other sites More sharing options...
coops Posted October 5, 2007 Author Share Posted October 5, 2007 Thanks, but I have realised its something to do with the form... as I inputted it into the function without the form and all was ok..... Does anyone know anyway that you can resolve this on the form side? Link to comment https://forums.phpfreaks.com/topic/71953-%C2%A3-in-a-variable/#findComment-362399 Share on other sites More sharing options...
Yesideez Posted October 5, 2007 Share Posted October 5, 2007 Can you post some HTML for the form? Link to comment https://forums.phpfreaks.com/topic/71953-%C2%A3-in-a-variable/#findComment-362402 Share on other sites More sharing options...
coops Posted October 5, 2007 Author Share Posted October 5, 2007 The code I'm using for the form is <form onsubmit="return check(this)" action="store.php" method="post" name="fromMain" target="_self" id="fromMain"> <input name="txtCustomerName" type="text" id="0"> and within store.php, I'm using a $_POST to retrieve the string Link to comment https://forums.phpfreaks.com/topic/71953-%C2%A3-in-a-variable/#findComment-362406 Share on other sites More sharing options...
Yesideez Posted October 5, 2007 Share Posted October 5, 2007 I'm presuming the pound sign is for a value - where would this be used? Link to comment https://forums.phpfreaks.com/topic/71953-%C2%A3-in-a-variable/#findComment-362407 Share on other sites More sharing options...
coops Posted October 5, 2007 Author Share Posted October 5, 2007 This will give a value of The £ sign comes from the form tho and then it goes into the original function (stated at the beginning), but Don't know why its converting the £ to a HTML code when changing the variable to a array.. But if it goes straight to an string and not using the form ITS ALL OK $value = "£" ; echo "Size ".strlen($value); while($i < strlen($value)){ $ia=0; echo "<br>".$value{$i}; $++; } This will show the correct data Link to comment https://forums.phpfreaks.com/topic/71953-%C2%A3-in-a-variable/#findComment-362438 Share on other sites More sharing options...
Yesideez Posted October 5, 2007 Share Posted October 5, 2007 First remove that $value= line. while($i < (strlen($value)+1)){ See how that works. Personally I'd forget adding a pound sign into the equation at all and stick to using it in HTML only. Link to comment https://forums.phpfreaks.com/topic/71953-%C2%A3-in-a-variable/#findComment-362443 Share on other sites More sharing options...
GingerRobot Posted October 5, 2007 Share Posted October 5, 2007 Erm, i hate to say it but you're rather re-inventing the wheel with your function. Try the htmlentities() function. Link to comment https://forums.phpfreaks.com/topic/71953-%C2%A3-in-a-variable/#findComment-362444 Share on other sites More sharing options...
coops Posted October 5, 2007 Author Share Posted October 5, 2007 Sadly I need the pound Sing as the function goes through a string to look for character that affecting XML and converts it into the HTML code and then inputs the new string into XML. The data comes from a form, using $_POST so $value = $_POST... then the $Value is converted to an array $value{}... Then it loops around looking for the characters that will affect XML and replace them... But using $_POST already converts £ and ' ... but does not convert any other character that will affect XML....... Link to comment https://forums.phpfreaks.com/topic/71953-%C2%A3-in-a-variable/#findComment-362447 Share on other sites More sharing options...
Yesideez Posted October 5, 2007 Share Posted October 5, 2007 Check GingerRobot's reply with the link he posted. Link to comment https://forums.phpfreaks.com/topic/71953-%C2%A3-in-a-variable/#findComment-362449 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.