Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Ok, I have page with something like this (I added 'scrapehere' string to make it easier to navigate, this page isn't 100% correct html and it has two identical fields with different values. No, I can't fix it because it's cms i'm using and i feel it would be too complicated for me to do):

scrapehere<input type="hidden" id="_someid" name="_somename" value="value"/>

I'm trying to get hidden value. So I wrote such script:

<?php
$data = file_get_contents('scrape-test.html');
$regex = '/scrapehere<input type="hidden" id="_someid" name="_somename" value="(.+?)"/';
preg_match($regex,$data,$match);
var_dump($match);
echo $match[1];
?>

But instead of my value script outputs this:

array(2) { [0]=>  string(74) "scrapehere  string(5) "value" } value

What's wrong with it, why won't it just print value? Did it already saved it somewhere but my echo is wrong? I want output to be just value.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
256 views
Welcome To Ask or Share your Answers For Others

1 Answer

var_dump($match);
echo $match[1];

both of these lines output data. var_dump outputs an array first element of which contains an input tag, which is not displayed in the browser because it's hidden!

so, if you want output to be only 'value', remove var_dump($match); from your code and let the echo do the job.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...