I am trying to split a name that I pull from a webpage using simple HTML DOM and the list and explode functions aren’t doing the trick. All I want to do is take a name {firstname middle(optional) lastname} and split them. The middle name only shows up on some names and it would be a bonus if I could handle that.
Here’s the code:
<?php
$data = new simple_html_dom();
$data->load_file("http://www.ratemyprofessors.com/ShowRatings.jsp?tid=861228");
$profName= $data->find("//*[@id=profName]", 0);
$profName = strip_tags($profName);
echo "Full Name: " . $profName = trim($profName);
list($first, $last) = explode(' ', "$profName ");
echo "first name: " . $first;
echo "last name: " . $last;
?>
My output reads:
Full Name: Jennifer Aaker
firstname: Jennifer Aaker
lastname:
try with: