Forum Moderators: coopster
I am a begginner in PHP, and I don't understand the syntax of regular expressions. Can anyone help me !
Site produces - this
<a href='/s/s/s/s.10057/'>Name (YYYY)</a>
<a href="something" onclick="something" onfocus="this.blur()"></a>
<a href="something" onclick="something" onfocus="this.blur()"></a>
<a href='/s/s/s/s.8000/'>Name2 (YYYY)</a>
<a href="something2" onclick="something2" onfocus="this.blur()"></a>
<a href="something2" onclick="something2" onfocus="this.blur()"></a> What I want is that the number inside the href (10057) and the text "Name (YYYY)". And I tryed many examples but because of the fact "/s/s/s/" seem to change and the number is with a word.
Please anyone help !
thanx for the rapid reply, but now I am kind of confused. Let me explain more of what I want, I want the number (from href), Name and the Year to be saved into the database (mysql). To do that I thought of having arrays then looping it to insert the items into the database. But i am not a fan of regular expressions, Can you give a brief info on what I need to do to succeed !?
Here is what I thought;
using preg_match_all make arrays on the number, name and the year - eliminating the other codes around then insert it to database.
What you think! (please give code examples - thank you)
Your logic sounds correct, now just apply the regular expression pattern to your string. You may be able to shorten that pattern if all you are after is the digits at the end followed by the path separator.
$pattern = '/<a href=["\'][^>]+\.(\d+)\/["\']>([^<]+)<\/a>/s';
preg_match_all($pattern, $subject, $matches);
print '<pre>';
print_r($matches);
print '</pre>';
exit;