Jump to content

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


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.

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.