Witam!
Mam taki mały problem. Potrzebuję wstawić część zewnętrznej strony treści swojej strony. Tu akurat z wyciągnięciem tagu <body> wraz zawartością i zmiany jego nazwy na div nie ma problemu. Ale do rzeczy.
W skrypcie używam skryptu: simplehtmldom ( http://simplehtmldom.sourceforge.net/ )
Problem polega na tym, że w pobieranej stronie trzeba podmienić linki tak by kliknięcie linku zewnętrznej strony nie przenosiło mnie do nowego okna.
to jest mój adres url:
http://10.1.1.24/strona/index.php?link=http://www.strona.pl/pl/index.php?option=com_content&view=category&layout=blog&id=1&Itemid=50
//$this->link = http://www.strona.pl/pl/index.php?option=com_content&view=category&layout=blog&id=1&Itemid=50
// $_SERVER["SERVER_NAME"].$_SERVER["PHP_SELF"] // 10.1.1.24/strona/index.php
function loadPageFromGet()
{
$this->link = $_GET["link"];
$arr = parse_url($this->link);
echo $this->link.'<br>';
print_r($arr);
$this->link = $_GET["link"];
//return;
$this->html->load_file($this->link);
$this->content = $this->html->find('body');
$this->content[0]->tag = 'div';
$this->content[0]->setAttribute('id', 'extern');
$this->modifyURLs($_SERVER["SERVER_NAME"].$_SERVER["PHP_SELF"].'?link='.$this->link);
}
private function modifyURLs($string )
{
$this->tags = $this->content[0]->find('a[href], form[action]');
foreach ($this->tags as $idx => $tag)
{
if(isset($this->tags[$idx]->href))
$this->tags[$idx]->href = $string.$this->tags[$idx]->href;
if(isset($this->tags[$idx]->action))
$this->tags[$idx]->action = $string.$this->tags[$idx]->action;
}
}
w wyniku dostaję coś takiego:
wysłane zapytanie
http://10.1.1.24/strona/index.php?link=http://www.strona.pl/pl/index.php?option=com_content&view=category&layout=blog&id=1&Itemid=50
serwer zrobił coś takiego
http://www.strona.pl/pl/index.php?option=com_content
Array ( [scheme] => http [host] => www.strona.pl [path] => /pl/index.php [query] => option=com_content )
wysłane zapytanie:
http://10.1.1.24/strona/index.php?link=http://www.google.pl/?biw=1366&bih=575&q=php+parse+url&oq=php+pars&aq=0&aqi=g10&aql=&gs_sm=e&gs_upl=3139980l3146339l0l28l26l11l4l0l2l553l3033l1.1.6.1.1.1&bav=on.2,or.r_gc.r_pw.&fp=32f72b32af09479c
serwer zrobił coś takiego
http://www.google.pl/?biw=1366
Array ( [scheme] => http [host] => www.google.pl [path] => / [query] => biw=1366 )
Jak widać fragment textu wysyłanego za pomocą GET jest ucinany i to tuż przed 2 parametrem.