Jump to content

PHP GURUS: How would you go about reading the source of an HTML page?


virtuexru

Recommended Posts

I need to read the source of an HTML page and be able to strip one 11 letter/number long key from it. Has to be done through PHP. I'm not so much worried about the stripping of the 11 letter/number but on how to use maybe:

 

fopen

 

To read the file?

How indepth do you want to go?

 

file puts the page into an array line by line file_get_contents puts it into a string and works with less code than cURL but is slower.

 

User preference imo.

 

I got to show the HTML. Now what I need to do is just strip Line 55:

 

<input type=hidden name=asd value="a490b986af96b1937b9d6ba6796acd11">

 

I need to strip it so I have a variable as: "a490b986af96b1937b9d6ba6796acd11"

<?php
$string = '<input type=hidden name=asd value="a490b986af96b1937b9d6ba6796acd11">';
list(,$string) = split("name=asd value=\"", $string);
list($value) = split("\"", $string);

echo $value;
?>

 

That would be the easiest. This can be done with regex, but I suck at that so yea.

this should do it:

 

$string = '<input type=hidden name=asd value="a490b986af96b1937b9d6ba6796acd11">';

preg_match('#name=asd value="(.*?)"#is', $string, $match);

echo $match[1]; 

 

Hope that helps.

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.