Jump to content

Having an issue with substr() / strpos()


hansman

Recommended Posts

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

 

 

Link to comment
https://forums.phpfreaks.com/topic/234897-having-an-issue-with-substr-strpos/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.