I notice you are still using your pcre as opposed to the ones bluewalrus and myself suggested. At least try not to use the pipe: | as a delimiter. The pipe has special meaning in pcre as the OR operator.
Printable View
I notice you are still using your pcre as opposed to the ones bluewalrus and myself suggested. At least try not to use the pipe: | as a delimiter. The pipe has special meaning in pcre as the OR operator.
Don't use it. It does not work. See my earlier posts and take a closer look at this post
when you insert basename($full_url) into a pcre like the above example you are actually looking for the exact phrase "basename" followed by the capture that you have named "full_url". To my knowledge php can't be inserted into pcre in the way that you are trying to do. With some modifiers you can insert php into your second part, $result, but that is something different.Code:preg_match ("|<[aA] (.+?)".basename($full_url)."(.+?)>(.+?)<\/[aA]>|i", $result, $matches);
"/<a href=\"(.*?)"/i"does not work for a couple reasons. The most obvious is that the second double quote is not escaped so that it is not recognized as a literal double quote. It should be"/<a href=\"(.*?)\"/i"
The other problem is that it is too simple and only accounts for very limited types of inputs. He is, however on the right track. I also know bluewalrus has a fair amount of experience with pcre as well.
The example script I gave you in an earlier post should find what you are looking for and put it into the variable $found. With $found compare it to your basename($full_url).
For example try adding the following:
It should look something like this:Code:$basename_url=basename($full_url);
if ($found=="$basename_url") echo "they matched";
PHP Code:<?php
$result = '<strong></strong><font face="Verdana" size="2"><br>
» </font><strong><a href="OtherMethods.php"><font face="Verdana" size="2">Other
Methods</font></a></strong>';
preg_match ('/(<a href=\")(.*?)(\?|\/\"|\")/i', $result, $matches);
$match=$matches[2];
if (substr($match,-1,1)=='/') $match=substr_replace($match,'',-1,1);
$match=explode("/","$match");
$found=end($match);
$full_url='http://www.site.com/OtherMethods.php';
$basename_url=basename($full_url);
print $found;
if ($found=="$basename_url") echo "<br>they matched";
else echo "<br>not found";
?>
it wont work, $result is a full html page with many links pulled by curl. I need something that looks inside all links looking for my basename() thats what my broken preg_match does.
just change preg_match to preg_match_all
However, now you will need to put $match into a loop of some sort, probably a "while" loop applying
to each part of the array. The above will need to be modified slightly.Code:$full_url='http://www.site.com/OtherMethods.php';
$basename_url=basename($full_url);
if ($found[]=="$basename_url") echo "<br>they matched";
else echo "<br>not found";
If you are having trouble with this let me know.
hey james this is almost working. Right now only fails on links that contain variables.
Like: "http://www.site.com/OtherMethods.php?error=1&whatever=2"
preg match only saves "http://www.site.com/OtherMethods.php?" from that URL, anyway to keep the entire URL?
can I see what the script you are using currently looks like? Remember, preg_match will only pull the first result it finds and that's it. preg_match_all will pull all of the results and store it into a multidimensional array, which I am not a big fan of pulling results from to be honest, but it all depends on your needs.
The script I presented only pullsfromPHP Code:OtherMethods.php?error=1&whatever=2
which is what I thought you wanted. If you want the entire url, I can probably write something up for you, but it will be different than what I was writing. I thought you specifically wanted the basename($full_url) as opposed to the full url for comparison purposes... Sorry about the lack of understanding of what you want on my part.Code:http://www.site.com/OtherMethods.php?error=1&whatever=2
Where $result is some site full HTML source, via curl.PHP Code:preg_match_all ('/(<a href=\")(.*?)(\?|\/\"|\")/i', $result, $matches);
for ($i=0;$i<sizeof($matches[2]);$i++)
{
if (basename($matches[2][$i]) == basename($links_full_url))
{
echo "found on link $i<br>";
break;
}
}
This is what is working for me but i have that variables problem. I do want the basename() or whatever is after the last "/", basename() on" http://www.site.com/OtherMethods.php?error=1&whatever=2" still returns "OtherMethods.php?error=1&whatever=2" and thats what i need to look for because some sites use wordpress or other CMS and their linking systems use variables to find the right pages.