2
Hello I would like your help with the following problem, which I have in this code.
function verificarParametro($loopurl,$urlHost) {
if (preg_match("/(\W|^){$urlHost}(\W|$)/i", $loopurl))
return true;
else
return false;
It checks the url by taking the parameter put in $urlHost
and checking in $loopurl
, if the true exists, otherwise the false.
Now here is my problem, I need you to do a complete check from start to end of the parameter that was specified in the field $urlHost
, even if it has any special characters or any other type of parameter, for example /*+-!|?\:
etc..
For example, if I put to search this parameter below, will give line error.
if (verificarParametroA('https://drive.google.com/file/d/abcdfghiglmnopqrstuvxz/
', 'drive.google.com/file/d/')) {
echo 'Sim'; }
Use preg_quote($urlHost,'/') to escape the URL. But I think you’re using ER for something you don’t need, a php strpos() would solve!
– Wilson Faustino
Note that the use of strpos and strips will also fail if you have something like this
verificarParametroA('https://foo.com?u=http://bar.com', 'bar.com')
, suggest theparse_url
: https://answall.com/a/305297/3635 - since the use ofstrpos
with(bool)
there in the other answer is totally mistaken, since the return0
would causefalse
, when in fact0
means that it found from the first character in strpos.– Guilherme Nascimento