w1ww Posted December 13, 2006 Share Posted December 13, 2006 Hello :)Well I'm new to the PHP 'world' and I'm trying to create an PHP script that extracts an url from this link. For example :http://news.google.com/news/url?sa=T&ct=pt/17-0&fd=R&url=http://www.estadao.com.br/ultimas/nacional/noticias/2006/dez/13/2.htm&cid=1103238007&ei=8mmARcKVMb7maOid1dIOSo the script should extract what is between "url=" and the "&cid..." that in this case is http://www.estadao.com.br/ultimas/nacional/noticias/2006/dez/13/2.htmI don't know if it is easy or hard to do .. But well, just asking! Thank you! Link to comment https://forums.phpfreaks.com/topic/30552-extracting-url/ Share on other sites More sharing options...
kenrbnsn Posted December 13, 2006 Share Posted December 13, 2006 All the variables in the URL are available in the $_GET superglobal array. You would want $_GET['url']Ken Link to comment https://forums.phpfreaks.com/topic/30552-extracting-url/#findComment-140652 Share on other sites More sharing options...
genericnumber1 Posted December 13, 2006 Share Posted December 13, 2006 If you are processing the URL from a string, and not your current page... eg if you are processing the news.google.com string, it's obvious that you aren't google.com so you'd want to look at the function outlined here...http://simon.net.nz/articles/process-a-url-query-string-in-php/ Link to comment https://forums.phpfreaks.com/topic/30552-extracting-url/#findComment-140660 Share on other sites More sharing options...
w1ww Posted December 13, 2006 Author Share Posted December 13, 2006 $_url = $_xml_sources[$nIndex]["url"];This is on the Rss feed reader that I've. It gets the url and save it on the variable! all I want its to create another variable before this one that save the url and after it extracts it .. Isnt it possible?Many thanks :) Link to comment https://forums.phpfreaks.com/topic/30552-extracting-url/#findComment-140669 Share on other sites More sharing options...
alpine Posted December 13, 2006 Share Posted December 13, 2006 Try:[code]<?php$url = "http://news.google.com/news/url?sa=T&ct=pt/17-0&fd=R&url=http://www.estadao.com.br/ultimas/nacional/noticias/2006/dez/13/2.htm&cid=1103238007&ei=8mmARcKVMb7maOid1dIO";preg_match('/&url=(.*?)&cid=/', $url, $result);echo $result[1]; // http://www.estadao.com.br/ultimas/nacional/noticias/2006/dez/13/2.htm?>[/code] Link to comment https://forums.phpfreaks.com/topic/30552-extracting-url/#findComment-140704 Share on other sites More sharing options...
kenrbnsn Posted December 13, 2006 Share Posted December 13, 2006 You can also use a combination of the [url=http://www.php.net/parse_url]parse_url()[/url] and [url=http://www.php.net/parse_str]parse_str()[/url] functions:[code]<?php$url ="http://news.google.com/news/url?sa=T&ct=pt/17-0&fd=R&url=http://www.estadao.com.br/ultimas/nacional/noticias/2006/dez/13/2.htm&cid=1103238007&ei=8mmARcKVMb7maOid1dIO";$p_url = parse_url($url);echo '<pre>' . print_r($p_url,true) . '</pre>';parse_str($p_url['query'],$p_query);echo '<pre>' . print_r($p_query,true) . '</pre>';?>[/code]Ken Link to comment https://forums.phpfreaks.com/topic/30552-extracting-url/#findComment-140713 Share on other sites More sharing options...
w1ww Posted December 13, 2006 Author Share Posted December 13, 2006 Here I am again .. I modified the code to this (which gives an error) : "Warning: implode() [function.implode]: Bad arguments. in /home/ricardoq/public_html/lastnews/rss/getrss.php on line 20"This code gets the RSS feeds . In this case its for google! I'm new to PHP so probably I made a lot of erros changing the code! This code gets the RSS feeds . In this case its for google! [code]define("_NO_SESSION_",1);require_once("config.inc.php");$_count = $_GET["count"] ? $_GET["count"] : 10; $_items = getMyItems(); for($nIndex = 0; $nIndex < count($_xml_sources); $nIndex++){ if($_xml_sources[$nIndex]["use"]) { $_curr_time = mktime(date("H"), date("i"), date("s"), date("m"), date("d"), date("Y")); if($_curr_time >= $_xml_sources[$nIndex]["next"]) { $preurl = $_xml_sources[$nIndex]; preg_match('/&url=(.*?)&cid=/', $url, $newurl); $_url = $newurl[1]["url"]; $_file = _APP_PATH_ . "cache/" . md5($newurl[1]["url"]); $_content = implode("",file($_url)); $f = @fopen($_file,"w"); @fwrite($f,$_content); @fclose($f); $_url = $_file; $_diff = $_xml_sources[$nIndex]["next"] - $_xml_sources[$nIndex]["last"]; $_xml_sources[$nIndex]["last"] = $_xml_sources[$nIndex]["next"]; $_xml_sources[$nIndex]["next"] += $_diff; write_sources(); } else { $_file = _APP_PATH_ . "cache/" . md5($_xml_sources[$nIndex]["url"]); if(!file_exists($_file)) { @mkdir(_APP_PATH_ . "cache/"); $_content = implode("",file($_xml_sources[$nIndex]["url"])); $f = @fopen($_file,"w"); @fwrite($f,$_content); @fclose($f); } $_url = $_file; } $_tmp = parseXML($_url); } if(count($_xml_data)) $_xml_data = array_merge($_xml_data,$_tmp); else $_xml_data = $_tmp;}$_xml_data = noDuplicates($_xml_data);shuffle($_xml_data);for($nIndex = 0; $nIndex < $_count - count($_items); $nIndex++) $_all_items[] = $_xml_data[$nIndex];shuffle($_all_items);$_all_items = array_merge($_all_items,$_items);$_output = implode("",file(_APP_PATH_ . "templates/output.inc.php"));$_content = getContentParts($_output);$_print = $_content["before"];for($nIndex = 0; $nIndex < count($_all_items); $nIndex++){ $_tmp = $_content["item"]; $_tmp = str_replace("{TITLE}",$_all_items[$nIndex]["title"],$_tmp); $_tmp = str_replace("{URL}",$_all_items[$nIndex]["url"],$_tmp); $_tmp = str_replace("{DESCRIPTION}",$_all_items[$nIndex]["description"],$_tmp); $_print .= $_tmp;}$_print .= $_content["after"];echo $_print;exit;[/code][b]This is the original code: [/b][code]define("_NO_SESSION_",1);require_once("config.inc.php");$_count = $_GET["count"] ? $_GET["count"] : 10; $_items = getMyItems(); for($nIndex = 0; $nIndex < count($_xml_sources); $nIndex++){ if($_xml_sources[$nIndex]["use"]) { $_curr_time = mktime(date("H"), date("i"), date("s"), date("m"), date("d"), date("Y")); if($_curr_time >= $_xml_sources[$nIndex]["next"]) { $_url = $_xml_sources[$nIndex]["url"]; $_file = _APP_PATH_ . "cache/" . md5($_xml_sources[$nIndex]["url"]); $_content = implode("",file($_url)); $f = @fopen($_file,"w"); @fwrite($f,$_content); @fclose($f); $_url = $_file; $_diff = $_xml_sources[$nIndex]["next"] - $_xml_sources[$nIndex]["last"]; $_xml_sources[$nIndex]["last"] = $_xml_sources[$nIndex]["next"]; $_xml_sources[$nIndex]["next"] += $_diff; write_sources(); } else { $_file = _APP_PATH_ . "cache/" . md5($_xml_sources[$nIndex]["url"]); if(!file_exists($_file)) { @mkdir(_APP_PATH_ . "cache/"); $_content = implode("",file($_xml_sources[$nIndex]["url"])); $f = @fopen($_file,"w"); @fwrite($f,$_content); @fclose($f); } $_url = $_file; } $_tmp = parseXML($_url); } if(count($_xml_data)) $_xml_data = array_merge($_xml_data,$_tmp); else $_xml_data = $_tmp;}$_xml_data = noDuplicates($_xml_data);shuffle($_xml_data);for($nIndex = 0; $nIndex < $_count - count($_items); $nIndex++) $_all_items[] = $_xml_data[$nIndex];shuffle($_all_items);$_all_items = array_merge($_all_items,$_items);$_output = implode("",file(_APP_PATH_ . "templates/output.inc.php"));$_content = getContentParts($_output);$_print = $_content["before"];for($nIndex = 0; $nIndex < count($_all_items); $nIndex++){ $_tmp = $_content["item"]; $_tmp = str_replace("{TITLE}",$_all_items[$nIndex]["title"],$_tmp); $_tmp = str_replace("{URL}",$_all_items[$nIndex]["url"],$_tmp); $_tmp = str_replace("{DESCRIPTION}",$_all_items[$nIndex]["description"],$_tmp); $_print .= $_tmp;}$_print .= $_content["after"];echo $_print;exit;[/code]Well, I think is asking too much for someone to check the code but :\ I'm stuck on this! Thanks in advance! Link to comment https://forums.phpfreaks.com/topic/30552-extracting-url/#findComment-140723 Share on other sites More sharing options...
w1ww Posted December 14, 2006 Author Share Posted December 14, 2006 Checking the original code I've noticed that I need to change the code at least 3 times .. that is when the script gets de url from the feed .. Any help? Link to comment https://forums.phpfreaks.com/topic/30552-extracting-url/#findComment-141071 Share on other sites More sharing options...
w1ww Posted December 14, 2006 Author Share Posted December 14, 2006 I'br nrrn playing wirh it but it always give this error:[code]Warning: implode() [function.implode]: Bad arguments. in /home/ricardoq/public_html/lastnews/rss/getrss.php on line 20[/code]I'm without ideas :| Link to comment https://forums.phpfreaks.com/topic/30552-extracting-url/#findComment-141118 Share on other sites More sharing options...
w1ww Posted December 14, 2006 Author Share Posted December 14, 2006 no one? Link to comment https://forums.phpfreaks.com/topic/30552-extracting-url/#findComment-141367 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.