like this?
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; } }
like this?
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; } }
To choose the lesser of two evils is still to choose evil. My personal site
no, preg_match already stores the URLs in the array without the variables
The array also seems to be broken when print_r() so i guess the "&" from the URLs is braking it?
It is working for me. When using print_r() try using your browser to view the source. When you do you will see that the results are a little bit different. You will also notice that the match is found.
Here is the script I was working with:
PHP Code:<pre><?php
$links_full_url="http://www.site.com/OtherMethods.php?error=1&whatever=2";
$g=basename($links_full_url);
$result = '<strong></strong><font face="Verdana" size="2"><br>
» </font><strong><a href="http://www.site.com/OtherMethods.php?error=1&whatever=2"><font face="Verdana" size="2">Other
Methods</font></a></strong>';
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;
}
}
print_r($matches);
?></pre>
To choose the lesser of two evils is still to choose evil. My personal site
nicmo (11-28-2010)
thanks james its working, i had the wrong preg_match for god knows why...
I started testing and after 4 positive sit checks i got my first problem.
because if the class, it is not found. Also, some sites use:Code:<a class="fadeThis " href="http://www.site.com/OtherMethods.php">
No space between a and href, just a line break. Also cannot be found ofcourse. I guess this can be done by adding some extras to the preg_match, could you help me once more? :PCode:<a href="http://www.site.com/OtherMethods.php">
My goal is to try and keep the preg_match_all simple as it is with most scripting. We can get more complicated as needed. For now try replacing
withPHP Code:preg_match_all ('/(<a href=\")(.*?)(\/\"|\")/i', $result, $matches);
PHP Code:preg_match_all ('/(href=\")(.*?)(\/\"|\")/i', $result, $matches);
To choose the lesser of two evils is still to choose evil. My personal site
would you have any other suggestion to try and keep the "<a "? I really need to make sure its a proper link else people will cheat my system.
how about
PHP Code:preg_match_all ('/(<a.*?href=\")(.*?)(\/\"|\")/i', $result, $matches);
To choose the lesser of two evils is still to choose evil. My personal site
nicmo (11-29-2010)
that does work with classes and onclicks, etc. However sites that for some reason have their HTML displayed like this site: http://www.secnews.gr/ the preg_match cant find any links. Does .*? include "" or line breaks?
Code:<a href="http://www.site.com/OtherMethods.php">
try this
In the pcre that we have been working with thus far we have been using thePHP Code:preg_match_all ('/(<a.*?href=\")(.*?)(\/\"|\")/is', $result, $matches);
imodifier, which makes the pcre case insensitive. Thesmodifier will tell the pcre to capture newlines with the dot metacharacter. For whatever reason, the newline is a whitespace character that the dot metacharacter will not capture by default.
sorry about earlier. when you were saying linebreaks earlier I thought you were talking about<br>
Last edited by james438; 11-29-2010 at 03:59 PM. Reason: added last sentence.
To choose the lesser of two evils is still to choose evil. My personal site
nicmo (11-29-2010)
Thats awsome James, you saved my baconregex is a little too much info for me right now, hopefully i will grasp it soon.
So far, all the tests are working.
Bookmarks