How to put the querystring name in php?
$file_get_html('http://localhost/search/?q=');
And when accessing localhost/?name=example
the code looks like this
$file_get_html('http://localhost/search/?q=example');
I do not know how to put $_GET['url']
inside a php :(
Cœur
38.9k25 gold badges206 silver badges281 bronze badges
3 Answers 3
The question isn't very clear, but I suspect this is the answer:
file_get_html('http://localhost/search/?q=' . urlencode($_GET['url']));
answered Jun 20, 2013 at 0:35
-
Notice: Undefined variable: file_get_html in C:_server\htdocs\test.php on line 7 Fatal error: Function name must be a string in C:_server\htdocs\test.php on line 7 line 7:
$html = $file_get_html('http://localhost/bsearch/?q=' . urlencode($_GET['movie']));
Theus– Theus2013年06月20日 02:21:15 +00:00Commented Jun 20, 2013 at 2:21 -
Didn't you see the comment I wrote an hour ago? There shouldn't be a
$
beforefile_get_html()
.Barmar– Barmar2013年06月20日 02:30:15 +00:00Commented Jun 20, 2013 at 2:30 -
Oh, sorry. Worked. I thought the
$
in front offile_get_html
was standard for extensionTheus– Theus2013年06月20日 02:37:37 +00:00Commented Jun 20, 2013 at 2:37 -
$
is for variables in PHP, I don't know where you got the idea it had anything to do with extensions.Barmar– Barmar2013年06月20日 02:38:12 +00:00Commented Jun 20, 2013 at 2:38 -
Although I know very little PHP, I know that the
$
is all PHP variables. However, I thought it was necessary for the extension to work$
. Anyway.Theus– Theus2013年06月20日 02:41:29 +00:00Commented Jun 20, 2013 at 2:41
The ?q=example will let you use something like $example = $_GET['q'], and $example should equal the value of q in your querystring.
If you have a querystring that looks like this:
?q=example&url=myurl.com
You can access the q and url parameters like this:
$q = $_GET['q']; // which will equal 'example'
$url = $_GET['url']; // which will equal 'myurl.com'
If that is what you are trying to do.
answered Jun 20, 2013 at 0:35
-
But how to put in
$file_get_html
?Theus– Theus2013年06月20日 02:25:55 +00:00Commented Jun 20, 2013 at 2:25
$url = urlencode($_GET['url']);
$contents = file_get_contents("http://localhost/search/?q={$url}");
var_dump($contents);
answered Jun 20, 2013 at 2:32
lang-php
$
beforefile_get_html
URL
have to do with the parameterq
that you are showing? can you better explain what is is you are trying to do?<?php // setup require_once('simple_html_dom.php'); // get DOM from URL or file $html = $file_get_html('http://localhost/serarch/?q='); ?>
Wanna use the Simple HTML DOM Parser to extract data of a page. However, this page is a result of seek. So, I replace the variable in my url, the site url [search].