Forum Moderators: coopster

Message Too Old, No Replies

Regex help needed

how to write proper regex for...

         

phparion

9:27 am on Nov 25, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Hi dear fellows,

I have been trying to fetch student names from html source code of a page but i am not able to do it properly and hence need your wise words on it ,

here is my code,

PHP Code:
preg_match_all("/<a href=\"javascript:
document.viewForm.studentID.value='([0-9])*'; viewInfo
();\" onMouseOver=\"window.status='Visit Marks Sheet';
return true;\" onMouseOut=\"window.status=''; return true;
\">(.*?)<\/a>/i", $result, $matches2);

Where

- $result holds html output,
- value='([0-9])*' in fact here the value can different for each user , it is his ID and can be any digit so i used 0-9 with * but i am not sure if it is the right way to do it,
- ">(.*?)<\/a>/ here is what i actual want to fetch out , (.*?) contains the name of the student and i have to fetch all names as an array ..

for now i get emptry array of arrays (3 sub arrays)

.. the real SOURCE can be like,

Code:
<a href=\"javascript:
document.viewForm.studentID.value='6543'; viewInfo
();\" onMouseOver=\"window.status='Visit Marks Sheet';
return true;\" onMouseOut=\"window.status=''; return true;
\">jojoba<\/a>

please help on writing an accurate regex for it.

thanks

mcibor

8:17 pm on Nov 26, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I think it should be

preg_match_all("/<a href=\"javascript:
document.viewForm.studentID.value='([0-9]*)'; viewInfo
\(\);\" onMouseOver=\"window.status='Visit Marks Sheet';
return true;\" onMouseOut=\"window.status=''; return true;
\">(.*?)<\/a>/i", $result, $matches2);

or just match any 4 digit number
([0-9]{4}) and anything before </a>
(.*?)<\/a>

Hope this helps - didn't test it.
Michal