phphtmlstringbackslashstripslashes

How to remove the additional(extra) backslashes present in HTML anchor tags?


I've following HTML string present in a variable titled $text:

$text = <a title=\"\" href=\"https://www.filepicker.io/api/file/TXSta27QzqDnLeBXrZvX\"><img src=\"https://www.filepicker.io/api/file/TXSta27QzqDnLeBXrZvX\" height=\"150px\" width=\"150px\"></a>

<a href=\"https://www.filepicker.io/api/file/TXSta27QzqDnLeBXrZvX\" class=\"comment_attach_image_link_dwl\">Download</a>;

I want to remove those extra backslashes present in the HTML string. I f you observe closely these backslashes are present within the attributes as well like in title, src, height, width, etc. I want to remove all of them and want a final cleaned up HTML string.

It's not always that these extra backslashes are present in a HTML string. Sometimes it present, sometimes it's not. So the check for presence of these additional backslashes should also be performed. Only upon their presence the clean up operation should be carried out.

How should I do it in an reliable and efficient way?

Thanks.


Solution

  • Can you please try the following function:

    <?php
    echo stripslashes("Who\'s Peter Griffin?");
    ?>
    

    Output:

    Who's Peter Griffin?