John Davidson

php - Check if url exist in array list of URLS retrieved from database

0 comments
Message:


I am trying to compare the current URL with the URLs retrieved from the database but for some reason only works if it matches the first array.


   $url = get_permalink();
function check_links($url){
$db_links= get_option('db_links');

$exclude = explode(',',$db_links);

if(in_array($url, $exclude)){
echo "display:none";
}

}

After I dump $exclude, I get


array(3){
[0]=>string(16) "https://test.com"
[1]=>string(18) "https://test.com/2"
[2]=>string(19) "https://test.com/22"
[3]=>string(20) "https://test.com/235"
}

I want to compare my current URL with the list above. If it shows I want to echo "display:none";
My current URL is https://test.com/22


if(in_array($url, $exclude)){
echo "display:none";
}

I found out that it works only if my URL is https://test.com, for other cases it doesn't work.



My Answer:
"URL exists in array list";_ } else {_ echo "URL does not exist in array list";_ }_}_check_links($url);

Rate this post

5 of 5 based on 9382 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us