Jump to content

Recommended Posts

Wondering how to grab pieces of text from a file.

Let's say I opened a webpage and want to have all the values of the input fields.

This would be the contents of the file

<html>
<head>
...
</head>
<body>
...
<input type='hidden' name='hidden_w' value='123456' />
...
</body>
</html>

Now I want that value of the input field 'hidden_w' to be in the variable $w.

How do I this? (w. explanation please)

-- iLLeLogicaL --

sorry... by file i mean string...

 

$file=file_get_contents('url.html');
$inputs=strip_tags($file,'<input>');
echo $inputs; #may contain '<input type=textbox name="" value="">asdfasdf<input type=submit>there could be a paragraph or two in here...<input type=file name="">asdfadf'

 

i jus made this... you can scrap the text outta that string too with this...

 

<?php
function strip_text($string){
$tag=false;
$strlen=strlen($string);
for($i=0; $i<$strlen; $i++){
  if($string{$i}=='<') $tag=true;
  elseif($string{$i}=='>'){
   $out.=$string{$i};
   $tag=false;
  }
  if($tag==true) $out.=$string{$i};
}
return $out;
}
?>

 

 

so....

 

 

$file=file_get_contents('url.html');
$inputs=strip_tags(strip_text($file),'<input>');
echo $inputs; #may contain '<input type=textbox name="" value=""><input type=submit><input type=file name="">'

try

<?php
$text ="<html>
<head>
...
</head>
<body>
...
<input type='hidden' name='hidden_w' value='123456' />
...
<input type='hidden' name='hidden_x' value='654321' />
<input type='hidden' name='y' value='654321' />
</body>
</html>";
$out = array();
$text = str_replace("'",'"',$text);
//find hidden inputs
preg_match_all ('/<input[^>]+hidden[^>]+>/',$text,$b);
$x = $b[0];
foreach ($x as $a){
//find name properties
preg_match('/name="([^"]+)"/',$a,$c);
$key = $c[1];
$key = str_replace('hidden_','', $key);
//find value
preg_match('/value="([^"]+)"/',$a,$c);
$value = $c[1];
$out[$key] = $value;
}
print_r($out);
?>

Nah that just makes it worse  :o

Ok let's say this.

I know that when I load the page there are always 5 fields, 3 who're hidden, and 3 who's name change everyday (wonder why? :P)

But I know that the last 3 are always empty (as is the first one). But it only shows me the name of the 3 first fields, then stops after the 3 field (no value's in array but still 2 fields are after that

<input type="hidden" name="w" value="">
<input type="hidden" name="login" value="999999999"><!-- CHANGING VALUE -->

<p><table class="p1" style="width:100%"cellspacing="1" cellpadding="0"><tr><td>

<table width="100%" cellspacing="1" cellpadding="0">
<tr><td><label>Naam:</label>
<input class="fm fm110" type="text" name="e9b0679" value="" maxlength="15"> <span class="e f7"></span><!-- CHANGING NAME -->
</td></tr>
<tr><td><label>Wachtwoord:</label>
<input class="fm fm110" type="password" name="e5cd2eb" value="" maxlength="20"> <span class="e f7"></span><!-- CHANGING NAME -->

</td></tr>
</table></td></tr></table></p>


<p align="center"><input type="hidden" name="ec75e7c" value=""><!-- CHANGING NAME -->

Now I want the names contained in array dunnow named $names or so, and the values in a container name $values with a cifer as index ::)

I may be asking to much, but we all need to learn don't we :P?

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.