2

I've been working on a small side project which formats Skype logs to make them look nice. This is going great, but I have hit a somewhat annoying bump in the road.

Here is a great (and somewhat obscene) example of what is going on. As you can see, htmlspecialchars() also converts HTML character codes into a string (because & becomes &). I was wondering if there was a way to allow HTML entities to still remain through htmlspecialchars?

mattrick
  • 3,580
  • 6
  • 27
  • 43

2 Answers2

0

You can use htmlentities() if it solve your problems, else store the string in one variable which returns from the functions and then while printing that string

$foo = str_replace("&","&","$bar"); 
Sarvagna Mehta
  • 334
  • 3
  • 16
0

Use this function:

$string=$_POST[pname];
function seoUrl($string) {
    //Lower case everything
    $string = strtolower($string);
    $string = str_replace('&',' ',$string);
    $string = preg_replace("/[^a-z0-9_\s-]/", "", $string);
    $string = preg_replace("/[\s-]+/", " ", $string);
    $string = preg_replace("/[\s_]/", "-", $string);
    return $string;
}
$sclean=seoUrl($string);

You can use str_replace('&',' ',$string); instead of & use what character you want remove...

Bruce
  • 1,647
  • 4
  • 20
  • 22