Forum Moderators: coopster
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
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