View Full Version : mySQL wont all % sign

02-11-2008, 07:04 PM
I'm creating a CMS for this client that wants to be able to update their own pages. I set up a wysiwyg editor that pulls the HTML code that is stored in a database but I'm having some issues with the % sign. Whenever I put in the editor ex: 15% off, it kicks out a message saying "query is empty".

It will allow all other signs.

Any ideas?

02-11-2008, 07:26 PM
Sounds like the issue is not with mysql. This is probably an issue with the WYSIWYG editor. These are notorious for screwing up html code when incorporated with a CMS.

My suggestion is to change the editor to "code view" (i think most editors have this function) and use the "raw" code for these characters.

Percentage sign:
% for numerical code
% for Hex Code

In order to fix it permenantly, I think you need to recode the editor itself or at least add this character. I'm not sure where you would start with that.

02-11-2008, 07:31 PM
Percentage sign:
% for numerical code
% for Hex Code

sorry, i forgot to change this to code view. That part should read:

Percentage sign:
<code>%</code> for numerical code
&#x25; for Hex Code

02-11-2008, 07:33 PM
lets try this one last time


02-11-2008, 07:38 PM
I'm not sure why this won't work... just remove the underscores for the code for the % character.


02-11-2008, 07:52 PM
isnt there something in php that will take a word or in this case a sign and replace it with something else. So in this case it will take any % signs and replace it with &#x25;

kinda like how some site if you put in a curse word it will replace it with something like @#$%^#

02-11-2008, 08:00 PM
I think this is what im looking for str_replace



$text ="This item is 15% off today!";

$oldWord ="%";
$newWord ="&#x25;";

$text = str_replace($oldWord , $newWord , $text);

echo $text;


02-11-2008, 08:16 PM
If you want to replace all the % with code you would code something like:

$symbol = array('%');
$replacements = array('$#37;');


$content = str_replace($symbol, $replacements, $content);

I don't think this is this is the best way to do it. Probably better to set those values in the actual editor script, but thats how you find/replace with php.

02-11-2008, 08:19 PM
looks like you got it. i would use the numerical code


rather than &#x25; the hex code.

02-11-2008, 08:23 PM
Thanks for the help.

02-11-2008, 08:26 PM
Now you used an array incase there is more then 1 word that needs to be replaced correct?

02-12-2008, 12:53 AM
yup, you can add as many symbols/ words as you want. just make sure you have a coressponding "replacement" word in the $replacements array.

this also works well if you are using an language filter.