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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.