hansman Posted April 27, 2011 Share Posted April 27, 2011 So I am trying to extract a title out of an external webpage. There code on the external page is this.. <td valign="top" align="left"><font class="resultCourse"><u>Introduction to Java</u></font></td> </tr> <tr> <td colspan="2"><img src="/images/spacer.gif" height="3" width="1" alt="spacer"></td> </tr> <tr> <td colspan="2" align="center"> </td> </tr> </table> </td> </tr> </table> </td> </tr> <tr bgcolor="#FFFFFF"> <td align="left" valign="top"><font class="resultDesc"><font class="resultDescTitle"><u>Description</u></font>: <p>Fall, Spring <br> This course provides software developers with the knowledge and skills to use Java to build Internet and Intranet applets and Windows applications. Topics include overview of the Java virtual machine, Java classes and method, instantiating Java objects, access method, creating Java applets, the Java applet life cycle, inheritance and polymorphism, and Java class libraries.</p> </font></td> </tr> I am trying to pull out just "Introduction to Java." However, this must work across many different pages. The page describes a course, it needs to work with all courses. Here is what I wrote in PHP to pull it. ($returned_content is the URL) $courseStart = "Introduction to"; $courseFinish = "</u></font></td>"; $cpos = strpos($returned_content, $courseStart); echo $cpos; $cpos1 = strpos($returned_content, $courseFinish); $ctotal = $cpos1 - $cpos; echo substr($returned_content, $cpos, $ctotal). "<br>"; This will pull out "18095Introduction to Java" My question is, what should i make $courseStart so that no matter what class is listed, it will output it on my side. If I use the HTML code ( <font class="resultCourse"><u> ) It wont work. Thanks in advance for any help Quote Link to comment Share on other sites More sharing options...
gizmola Posted April 27, 2011 Share Posted April 27, 2011 This type of problem is best handled using regular expressions. Use the preg_match() function. preg_match Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.