简体   繁体   中英

Cannot remove double quotes from string PHP

Have tried every solution here and still nothing. This is var_dump string(19) ""Example"" . I just need to remove double quotes from name so "Example" should be Example Tried with trim, preg_replace, substr .

I think that there is problem somewhere else but I dont have much experience with PHP so I am stuck.

Here we go:

<?php
$str = '""Example""';
$str = str_replace('"', '', $str);
echo $str;
?>

You can even see a demo on ideone.com .

If

str_replace('"', '', $a)

does not work, maybe that is not a single double quote, but it's analogue, like ¨

Try trim($string, '&#x22;'); and take some time to learn about HTML entities .

What's happening is the double quotes are html entities, so as you've seen in var_dump the string is not "Movie Title" but &x#22;Movie Title&x#22; . There is no literal double quote in the string for the function to trim, so it fails. You need to trim the entity instead.

这工作:

$string = trim(html_entity_decode($string),'"');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM