Using double quotes on str_replace

Alê Moraes

I'm trying to use str_replace to change my code:

$changeli = "li id=\"head{$raiz}\" class=\"head\"";
$changeli2 = "li id=\"foot{$raiz}\" class=\"foot\"";

echo $changeli; // result li id="head-all" class="head"
echo $changeli2; // result li id="foot-all" class="foot"

$footer = str_replace($changeli, $changeli2, $footer );

It doesn't work, but when I remove the text up to the double quotes, it works, as follows:

$changeli = "head{$raiz}";
$changeli2 = "foot{$raiz}";

echo $changeli; // result head-all
echo $changeli2; // result foot-all

$footer = str_replace($changeli, $changeli2, $footer );

Can someone help me?

ib11

Better yet, try to use ' instead of " for the outer quote so you don't have to escape it at all. And concatenate $raiz with your string. The problem is most likely characters that should be escaped in html.

Try this, this works (see this code exactly here):

$changeli = 'li id="head'.$raiz.'" class="head"';
$changeli2 = 'li id="foot'.$raiz.'" class="foot"';

// value of $raiz is "-all" at this point (for clarity of code)
echo $changeli; // result should be li id="head-all" class="head"
echo $changeli2; // result should be li id="foot-all" class="foot"

$footer = htmlspecialchars_decode(str_replace(htmlspecialchars($changeli), htmlspecialchars($changeli2), htmlspecialchars($footer)));

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Are there different types of double quotes in utf-8 (PHP, str_replace)?

From Dev

Replace double quotes that are not escaped using sed

From Dev

Using Regex to replace double quotes in the middle of a word

From Dev

Replace double quotes into single quotes?

From Dev

Using double quotes within double quotes

From Dev

Using double or no quotes with wildcards

From Dev

how to add double quotation character in PHP string using str_replace

From Dev

Replace Double quotes with space

From Dev

Using a function in str_replace

From Dev

Using sed to replace a string that has parentheses and double-quotes

From Dev

Using sed to replace a string that has parentheses and double-quotes

From Dev

Replace single quotes with double quotes inside string

From Dev

Replace double quotes with single quotes in Postgres (plpgsql)

From Dev

replace single quotes and double quotes from a string

From Dev

Replace double quotes with single quotes in Postgres (plpgsql)

From Dev

Replace single quotes in double quotes in brackets

From Dev

Replace quotes to double quotes for alt attribute

From Dev

using double quotes and if condition in excel

From Dev

Using double quotes within a string

From Dev

Sed replace variable in double quotes

From Dev

Python:Replace tab in double quotes

From Dev

How to replace double quotes in a string?

From Dev

Replace double quotes to string empty

From Dev

groovy replace double quotes with single and single with double

From Dev

groovy replace double quotes with single and single with double

From Dev

Replace double quotes inside double quotes html attribute

From Dev

replace double quotes with back slash double quotes in shell script

From Dev

PHP str_replace tags with using arrays

From Dev

Using str_replace to alter the_title()

Related Related

  1. 1

    Are there different types of double quotes in utf-8 (PHP, str_replace)?

  2. 2

    Replace double quotes that are not escaped using sed

  3. 3

    Using Regex to replace double quotes in the middle of a word

  4. 4

    Replace double quotes into single quotes?

  5. 5

    Using double quotes within double quotes

  6. 6

    Using double or no quotes with wildcards

  7. 7

    how to add double quotation character in PHP string using str_replace

  8. 8

    Replace Double quotes with space

  9. 9

    Using a function in str_replace

  10. 10

    Using sed to replace a string that has parentheses and double-quotes

  11. 11

    Using sed to replace a string that has parentheses and double-quotes

  12. 12

    Replace single quotes with double quotes inside string

  13. 13

    Replace double quotes with single quotes in Postgres (plpgsql)

  14. 14

    replace single quotes and double quotes from a string

  15. 15

    Replace double quotes with single quotes in Postgres (plpgsql)

  16. 16

    Replace single quotes in double quotes in brackets

  17. 17

    Replace quotes to double quotes for alt attribute

  18. 18

    using double quotes and if condition in excel

  19. 19

    Using double quotes within a string

  20. 20

    Sed replace variable in double quotes

  21. 21

    Python:Replace tab in double quotes

  22. 22

    How to replace double quotes in a string?

  23. 23

    Replace double quotes to string empty

  24. 24

    groovy replace double quotes with single and single with double

  25. 25

    groovy replace double quotes with single and single with double

  26. 26

    Replace double quotes inside double quotes html attribute

  27. 27

    replace double quotes with back slash double quotes in shell script

  28. 28

    PHP str_replace tags with using arrays

  29. 29

    Using str_replace to alter the_title()

HotTag

Archive