if else statement - to echo class


#1

Hi,

I have a list of URL’s listed per line in file x.php:
[php]http://www.url1.com
http://www.url2.com
http://www.url3.com[/php]

Let’s say I have a link in my page with the following html code:
[php]


#2

Well, if the x.php file is not too large, you can read it into an array. Then, you can use the “IN ARRAY” function of PHP to find out if the url is in the array of urls. This would just be one command. Assuming the url’s have been loaded into an array called $urls and the target one to match is in $target, something like this would work:

[php]
if (in_array($target, $urls)) {
echo “listed”;
}else{
ehco “notlisted”;
}
[/php]
Fairly simple if you have the urls in an array!

If you have to do it by reading the text file, it would be easy, too. You can input one line at a time and trim the line and compare it. But, you would have to read the entire file each time. I would say it depends on how big a file you are talking about. If it is 10k or 100k, that is not much. So, a 50 character url, would mean about 2000 urls per 100k. Not much… So, why are you not doing this by way of a database? That would be faster than using a text file… Anyway, there you go… Good luck…