Question

I would want check if string is a valid xhtml/html. I have some html string get by tinymce editor. I would want in first time before save it into mysql database check if this html string is valid. I'm trying php tidy library:

    $html = '<div> <a href="#">a link</a> this is test <p>close tag error</p> </p> <p></p>';
    $tidy = new \tidy();
    $clean = $tidy->repairString($html,array(
        'output-xml' => true,
        'input-xml' => true
    ));

but it output this:

<div>\n<a href="#">a link</a>this is test \n<p>close tag error</p>other text \n<p></p></div>

so tags are closed correctly but tidy put /n characters. How can repair html without carriage return character?

Was it helpful?

Solution

You need to use htmlspecialhars_decode() to disable displaying of special characters...

$clean = htmlspecialchars_decode($clean);

OTHER TIPS

While not perfect (since it could destroy any actual carridge returns you have) the quick answer would be:

 $string = str_replace('\n', '', $originalString);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top