i have this piece of code which permits me to retrieve the information from a link... now, it says failed to open stream... here is the code:
Thanks!
$b = time ();
$date1 =date( "Y-m-d;h:i:s" , mktime(date("h")+6, date("i"), date("s"), date("m") , date("d"), date("Y")));
$str_time = "";
$str_msg = "";
$str_from = "";
$str_zip = "";
echo file_get_contents('href="http://testext.i-movo.com/api/receivesms.aspx?".$str_from."".$str_zip."".$phone."".$str_time."".$date1."".$str_msg.""');
}
This:
echo file_get_contents('href="http://testext.i-movo.com/api/receivesms.aspx?".$str_from."".$str_zip."".$phone."".$str_time."".$date1."".$str_msg.""');
Should be this:
echo file_get_contents("http://testext.i-movo.com/api/receivesms.aspx?".$str_from.$str_zip.$phone.$str_time.$date1.$str_msg);
please read the documentation for file_get_contents
the example says
$homepage = file_get_contents('http://www.example.com/');
echo $homepage;
you are using
$homepage = file_get_contents('href="http://www.example.com/');
now what is wrong ..
Related
I am going to make a URL checking system.
I have this URL
https://lasvegas.craigslist.org/mob/6169799901.html
Now I want to make this URL like this
https://lasvegas.craigslist.org/search/mob?query=6169799901
how can I do it using PHP?
Since I ended up (maybe?) solving it anyways, here's one method using URL/path parsing:
$url = 'https://lasvegas.craigslist.org/mob/6169799901.html';
$parsed = parse_url($url);
$basepath = pathinfo($parsed['path']);
echo $parsed['scheme'].
"://".
$parsed['host'].
"/search".
$basepath['dirname'].
"?query=".
$basepath['filename'];
Formatted for readability.
https://3v4l.org/E6Y54
Try this
$url = "https://lasvegas.craigslist.org/mob/6169799901.html";
$id = substr($url, strrpos($url, '/') + 1);
$id = str_replace(".html","",$id);
$result = "https://lasvegas.craigslist.org/search/mob?query=".$id;
echo $result;
Ltes say i want to copy a text from site ( http:// www.example.com/ex )
when i open http:/ /www.example.com/ex it shows this data click here
i want to copy every text after MrsId which is in between the double quotes(means i want to copy MN4D / CN4D / MK4D / MO4D all othese four codes from example.com/ex and these codes changes daily )
and sotre in a varible eg ( $a= 'MN4D', $b='CN4D' ,$c='MK4D' ,$d='MO4D' )
then want to use it as
$first = 'http:// www.example.com/?code=';
$url = "{$first}{$a}";
$urll = "{$firsts}{$b}";
$urlll = "{$firsts}{$c}";
$urlllll = "{$firsts}{$d}";
$result = file_get_contents($url);
$results = file_get_contents($urll);
$resultss = file_get_contents($urlll);
$resultsss = file_get_contents($urllll);
echo $result;
echo $results;
echo $resultss;
echo $resultsss;
I am serching for this code from 1 month but did't get success yet.
Change the code for your needs:
<?php
$json = '{"Amrlist":[{"Amcd":"mr-pub-4925511/1986","MrsId":"MN4D","BiclMine":"90","ImagePath":"http://my.example.com/myex/myex.jpg"},{"Amcd":"mr-pub-4925511/1986","MrsId":"CN4D","BiclMine":"90","ImagePath":"http://my.example.com/myex/myex.jpg"},{"Amcd":"mr-pub-4925511/1986","MrsId":"MK4D","BiclMine":"90","ImagePath":"http://my.example.com/myex/myex.jpg"},{"Amcd":"mr-pub-4925511/1986","MrsId":"MO4D","BiclMine":"90","ImagePath":"http://my.example.com/myex/myex.jpg"}]}';
$decoded = json_decode($json, true);
//var_dump($decoded);
$url = 'http://www.example.com/?code=';
foreach($decoded{'Amrlist'} as $Amrlist) {
//print_r($Amrlist);
print $url.$Amrlist['MrsId']."\n";
//print file_get_contents($url.$Amrlist['MrsId']);
}
/**/
?>
As I can see - data has json format. So you can use json_decode to access needed fields
I have this type of urls stored in a php variable:
$url1 = 'https://localhost/mywebsite/help&action=something';
$url2 = 'https://localhost/mywebsite/jobs&action=one#profil';
$url3 = 'https://localhost/mywebsite/info&action=two&action2=something2';
$url4 = 'https://localhost/mywebsite/contact&action=one&action2=two#profil';
I want to replace the page help, jobs, info, contact with home in a very simple way, something like this:
echo replaceUrl($url1);
https://localhost/mywebsite/home&action=something
echo replaceUrl($url2);
https://localhost/mywebsite/home&action=one#profil
echo replaceUrl($url3);
https://localhost/mywebsite/home&action=two&action2=something2
echo replaceUrl($url4);
https://localhost/mywebsite/home&action=one&action2=two#profil
So here is the solution i found:
function replaceUrl($page){
$pieces = explode("/", $page);
$base = '';
for ($i=0; $i<count($pieces)-1; $i++) $base .= $pieces[$i].'/';
$hash = strpbrk($pieces[count($pieces)-1], '&#');
return $base.'home'.$hash;
}
You'll want to add something like
RedirectMatch 301 help(.*) home$1
to your .htaccess file. I'm not sure PHP is the correct tool for the job.
If you actually want to modify a string with the value of that (which is what your tags and.. comments indicate), you'll want to do:
$url = "https://localhost/mywebsite/help&action=something#profil"
$url = str_replace("help", "home", $url);
echo $url; // https://localhost/mywebsite/home&action=something#profil
Hello I`m trying to echo the address where my php is so for example this is my address:
http://domain.com/index.php?route=product/product&path=20_27&product_id=41
I want a php that returns "domain.com/index.php?route=product/product&path=20_27&product_id=41"
I`ve got thus far to domain.com/index.php using :
<?php
$address = $_SERVER["HTTP_HOST"];
$address1 = $_SERVER["PHP_SELF"];
$address3 = "http://$adres$adres1";
$address4 = $adres3;
$address5 = $_SERVER["PATH_INFO"];
echo "$address4"; ?>
Can someone pls hlp ?
thx
Try this:
$url = $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
echo $url;
That's
$address = $_SERVER["HTTP_HOST"].$_SERVER["REQUEST_URI"]
To find out stuff like this is general create a php file with that content:
<?php
phpinfo();
?>
Open it in your browser and scroll to the bottom.
I have a script which I think is pretty basic scraping, call it what you will, but it takes on average at least 6 seconds...is it possible to speed it up? The $date variables are only there for timing the code and don't add anything significant to the time it takes. I have set two timing markers and each is approx 3 seconds between. Example URL below for testing
$date = date('m/d/Y h:i:s a', time());
echo "start of timing $date<br /><br />";
include('simple_html_dom.php');
function getUrlAddress()
{
$url = $_SERVER['HTTPS'] == 'on' ? 'https' : 'http';
return $url .'://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
}
$date = date('m/d/Y h:i:s a', time()); echo "<br /><br />after geturl $date<br /><br />";
$parts = explode("/",$url);
$html = file_get_html($url);
$date = date('m/d/Y h:i:s a', time()); echo "<br /><br />after file_get_url $date<br /><br />";
$file_string = file_get_contents($url);
preg_match('/<title>(.*)<\/title>/i', $file_string, $title);
$title_out = $title[1];
foreach($html->find('img') as $e){
$image = $e->src;
if (preg_match("/orangeBlue/", $image)) { $image = ''; }
if (preg_match("/BeaconSprite/", $image)) { $image = ''; }
if($image != ''){
if (preg_match("/http/", $image)) { $image = $image; }
elseif (preg_match("*//*", $image)) { $image = 'http:'.$image; }
else { $image = $parts['0']."//".$parts[1].$parts[2]."/".$image; }
$size = getimagesize($image);
if (($size[0]>110)&&($size[1]>110)){
if (preg_match("/http/", $image)) { $image = $image; }
echo '<img src='.$image.'><br>';
}
}
}
$date = date('m/d/Y h:i:s a', time()); echo "<br /><br />end of timing $date<br /><br />";
Example URL
UPDATE
This is actual what timing markers show:
start of timing 01/24/2012 12:31:50 am
after geturl 01/24/2012 12:31:50 am
after file_get_url 01/24/2012 12:31:53 am
end of timing 01/24/2012 12:31:57 am
http://www.ebay.co.uk/itm/Duke-Nukem-Forever-XBOX-360-Game-BRAND-NEW-SEALED-UK-PAL-UK-Seller-/170739972246?pt=UK_PC_Video_Games_Video_Games_JS&hash=item27c0e53896`
It's probably the getimagesize function - it is going and fetching every image on the page so it can determine the size. Maybe you can write something with curl to get the header only for Content-size (though, actually, this might be what getimagesize does).
At any rate, back in the day I wrote a few spiders and it's kind of slow to do, with internet speeds better than ever it's still a fetch for each element. And I wasn't even concerned with images.
I'm not a PHP guy, but it looks to me like you're going out to the web to get the file twice...
First using this:
$html = file_get_html($url);
Then again using this:
$file_string = file_get_contents($url);
So if each hit takes a couple of seconds, you might be able to reduce your timing by finding a way to cut this down to a single web-hit.
Either that, or I'm blind. Which is a real possibility!