0

why here str_replace not working

<?php
$str= '<div class=\"droppable\" ondrop=\"drop(event)\" ondragover=\"allowDrop(event)\"></div>';
echo str_replace('\"','"', $str);

i want to use str_replace with HTML tag.

2
  • Please define "not working". I tested your code and to me it seems to work. So tell us what output you expect and what output you actually get. Commented May 29, 2020 at 7:38
  • 2
    the output of your code is <div class="droppable" ondrop="drop(event)" ondragover="allowDrop(event)"></div> what's wrong with it? Commented May 29, 2020 at 7:38

1 Answer 1

1

As I get you want to remove the \s to get proper HTML.

Better way should be -

stripslashes('<div class=\"droppable\" ondrop=\"drop(event)\" ondragover=\"allowDrop(event)\"></div>');

Output

<div class="droppable" ondrop="drop(event)" ondragover="allowDrop(event)"></div>

stripslashes

Sign up to request clarification or add additional context in comments.

2 Comments

'\"' is literally a "slash-double-quote". It will be escaped in "\""
sss.. mistaken the quotes. :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.