&
has special meaning when used URIs. Your URI contains ¬
, which is a valid HTML entity on its own. It's being converted to ¬
, hence causing the trouble. Escape them properly as &not
to avoid this problem. If your data is fetched from elsewhere, you can use htmlspecialchars()
to do this automatically.
preg_replace replacing ¬ in string to funny character
-
30-06-2023 - |
Domanda
For some reason when preg_replace
sees ¬
in string and replaces it with ¬
:
$url= "http://something?blah=2&you=3&rate=22¬hing=1";
echo preg_replace("/&rate=[0-9]*/", "", $url) . "<br/>";
But the output is as follows:
http://something?blah=2&you=3¬hing=1 // Current result
http://something?blah=2&you=3¬hing=1 // Expected result
Any ideas why this is happening and how to prevent it?
Soluzione
Altri suggerimenti
Use this &
; in place of this &
because your &no
has special meaning
use this url :
http://something?blah=2&you=3&rate=22&nothing=1
and then do your replace accordingly
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow