Re: [PHP] calling a function in the same page
Jahangir wrote: I am trying to call a function from "a href" inside the same page. this is the code: echo "More results from Mysite"; // calling the function isearch function isearch($query) {$query=urlencode($query); $request='http://api.search.yahoo.com/WebSearchService/V1/webSearch?appid=Ja hangir&query=' .urlencode($query). '&output=php&results=100&site=mysite.com; $response=file_get_contents($request); if ($response === false) { die('Request failed');} $phpobj=unserialize($response); $count=$phpobj["ResultSet"]["totalResultsReturned"]; if($phpobj["ResultSet"]["totalResultsAvailable"]==0) {echo "NO RESULTS TO DISPLAY"; } echo ""; echo "Results from Mysite"; for($i=0;$i<$count;$i++) { echo ''; $no=$i+1; $url=$phpobj["ResultSet"]["Result"]["$i"]["Url"]; echo "" ."$no. ". "" . $phpobj["ResultSet"]["Result"]["$i"]["Title"] . ""; echo ""; echo ""; echo $phpobj["ResultSet"]["Result"]["$i"]["Summary"]; echo ""; echo ""; echo ""; echo "" .$phpobj["ResultSet"]["Result"]["$i"]["Url"] .""; echo ""; echo ""; $link=$phpobj["ResultSet"]["Result"]["$i"]["DisplayUrl"]; echo ""; echo "$link"; echo ""; echo ''; }} whenever i try to execute this function i either get an "Object not found error" or "Access Forbidden error". Can someone tell me where am i going wrong here?? thanks in advance why not use a temporary variable? $temp = isearch($query); echo "More results from Mysite"; -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] calling a function in the same page
You can not call PHP functions through a href which is used for linking web pages. You need to create a new file or use a switch in your current file for search input, with the function in it. So that you can link to that URL, not the function itself. You can use AJAX as well, to send commands to a php file and get the results in xml/text, but again you need to call Javascript there, your logic is totally wrong. Aras Koktas [EMAIL PROTECTED] Business Excellence Development Phi.dot Internet Systems -Original Message- From: Jahangir [mailto:[EMAIL PROTECTED] Sent: Sunday, December 24, 2006 6:34 PM To: php-general@lists.php.net Subject: [PHP] calling a function in the same page I am trying to call a function from "a href" inside the same page. this is the code: echo "More results from Mysite"; // calling the function isearch function isearch($query) {$query=urlencode($query); $request='http://api.search.yahoo.com/WebSearchService/V1/webSearch?appid=Ja hangir&query=' .urlencode($query). '&output=php&results=100&site=mysite.com; $response=file_get_contents($request); if ($response === false) { die('Request failed');} $phpobj=unserialize($response); $count=$phpobj["ResultSet"]["totalResultsReturned"]; if($phpobj["ResultSet"]["totalResultsAvailable"]==0) {echo "NO RESULTS TO DISPLAY"; } echo ""; echo "Results from Mysite"; for($i=0;$i<$count;$i++) { echo ''; $no=$i+1; $url=$phpobj["ResultSet"]["Result"]["$i"]["Url"]; echo "" ."$no. ". "" . $phpobj["ResultSet"]["Result"]["$i"]["Title"] . ""; echo ""; echo ""; echo $phpobj["ResultSet"]["Result"]["$i"]["Summary"]; echo ""; echo ""; echo ""; echo "" .$phpobj["ResultSet"]["Result"]["$i"]["Url"] .""; echo ""; echo ""; $link=$phpobj["ResultSet"]["Result"]["$i"]["DisplayUrl"]; echo ""; echo "$link"; echo ""; echo ''; }} whenever i try to execute this function i either get an "Object not found error" or "Access Forbidden error". Can someone tell me where am i going wrong here?? thanks in advance -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Downloading utf-8 encoded files
I want to download UTF-8 encoded kml files from a website. I have written a script that automatically downloads KML file. Problem is that some of the utf-8 charc are distrubed after saving file on windows. below is the script. . . . $handle = fopen($link, "rb"); $handle2= fopen("kml/$i.kml","w"); $contents = ''; while (!feof($handle)) { $contents = fread($handle, 8192); fwrite($handle2, $contents); } fclose($handle); fclose($handle2); . . . . Also, there is another problem.Downloading file using the above script, downloads incomplete file, means some of the information is skipped and file size is also small. Help would be appriciated -- Regards Fahad Pervaiz www.ecommerce-xperts.com
[PHP] pattern containing single quote in IF statement
I am stuck at a wierd problem. I am trying to do comparision between a "query string" and a "string value". the string consists of some diacriticals and single quotes. But when i try to escape the single quotes using backshash (\) it doesnt work. and when i try to use it inside a double quote preg_replace() doesnt recognise the code. why is php not comaparing string with single quotes?? here is the code: if($_GET['query']==new) { filter($query);} elseif($_GET['query']==some'u'all) { filter($query);} elseif($_GET['query']==all'u'ppl) { filter($query);} function filter($query) { $pattern = array ('/new/','/some'u'all/','/all'u'ppl/'); $rep = array ("new way","Some of you all ","all of you"); $op = preg_replace($pattern,$rep,$_GET['query']); echo "new value $op"; } also i wanted to just clarify is there a way of using multiple OR's in the same "if" condition i.e if(($_GET['query]')==new||newday||newtime||newbeginning||newthing) { // fn here; } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] calling a function in the same page
This is what you could do. Separating them into a few files. Also read the http://en.wikipedia.org/wiki/Ajax_%28programming%29 to learn some more about AJAX. You should also learn more about Server Side Scripting so you understand what can be done with Server Side Scripting and Client Side Scripting. index.php: $query would contain the SQL (or is it some other query type) you want to execute. This is far from any security as you come if this would be SQL, as you would output the SQL and therefore give table names etc to anyone who views the source of the HTML. This could in the future lead to SQL injections etc if you don't protect your self against that as well. You would also need to include the javascript.js in your tag of the HTML that you generate. Also you would need to download the Prototype library and include them in as well. See http://wiki.script.aculo.us/scriptaculous/show/Prototype where you can download the necessary files to do your AJAX calls. If you want to do it the hard coded way you need to create an ActiveXObject object if the user have IE or an XMLHttpRequest object if user don't have a IE compatiable browser. I suggest that you stick with Prototype unless you need to create an really high performance tool for this, and might need to hard code it your self. -- echo "More results from Mysite"; echo ""; -- javascript.js: -- function doSearch(sql) { var success = function(t){ thediv = document.getElementById("resultsdiv"); thediv.innerHTML = t.responseText; } var failure = function(t){ alert("Something went wrong, please try again."); } var url='ajax.php'; pars = "query="+ query; var req= new Ajax.Request(url, {method: 'post', postBody:pars, onSuccess: success, onFailure: failure}); } -- ajax.php -- //Set header to TEXT/HTML and also whatever enc type you want. header("Content-type: text/html"); if(isset($_POST['mysql'])) { //do whatever you want with the //$_POST['mysql'] variable and output the results //the you want to be shown in the div with id resultsdiv } -- Best regards, Peter Lauri -Original Message- From: Aras [mailto:[EMAIL PROTECTED] Sent: Tuesday, December 26, 2006 11:50 AM To: php-general@lists.php.net Subject: RE: [PHP] calling a function in the same page You can not call PHP functions through a href which is used for linking web pages. You need to create a new file or use a switch in your current file for search input, with the function in it. So that you can link to that URL, not the function itself. You can use AJAX as well, to send commands to a php file and get the results in xml/text, but again you need to call Javascript there, your logic is totally wrong. Aras Koktas [EMAIL PROTECTED] Business Excellence Development Phi.dot Internet Systems -Original Message- From: Jahangir [mailto:[EMAIL PROTECTED] Sent: Sunday, December 24, 2006 6:34 PM To: php-general@lists.php.net Subject: [PHP] calling a function in the same page I am trying to call a function from "a href" inside the same page. this is the code: echo "More results from Mysite"; // calling the function isearch function isearch($query) {$query=urlencode($query); $request='http://api.search.yahoo.com/WebSearchService/V1/webSearch?appid=Ja hangir&query=' .urlencode($query). '&output=php&results=100&site=mysite.com; $response=file_get_contents($request); if ($response === false) { die('Request failed');} $phpobj=unserialize($response); $count=$phpobj["ResultSet"]["totalResultsReturned"]; if($phpobj["ResultSet"]["totalResultsAvailable"]==0) {echo "NO RESULTS TO DISPLAY"; } echo ""; echo "Results from Mysite"; for($i=0;$i<$count;$i++) { echo ''; $no=$i+1; $url=$phpobj["ResultSet"]["Result"]["$i"]["Url"]; echo "" ."$no. ". "" . $phpobj["ResultSet"]["Result"]["$i"]["Title"] . ""; echo ""; echo ""; echo $phpobj["ResultSet"]["Result"]["$i"]["Summary"]; echo ""; echo ""; echo ""; echo "" .$phpobj["ResultSet"]["Result"]["$i"]["Url"] .""; echo ""; echo ""; $link=$phpobj["ResultSet"]["Result"]["$i"]["DisplayUrl"]; echo ""; echo "$link"; echo ""; echo ''; }} whenever i try to execute this function i either get an "Object not found error" or "Access Forbidden error". Can someone tell me where am i going wrong here?? thanks in advance -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] pattern containing single quote in IF statement
Quote: here is the code: if($_GET['query']==new) { filter($query);} elseif($_GET['query']==some'u'all) { filter($query);} elseif($_GET['query']==all'u'ppl) { filter($query);} Did you forget about "" around the strings? /Peter www.dwsasia.com - company web site www.lauri.se - personal web site www.carbonfree.org.uk - a way to reduce your carbon emissions and be a helping hand in the struggle against global warming -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: pattern containing single quote in IF statement
I tried that also but it didnt work. if($_GET['query']=="some'u'all") { filter($query);} I still get the same error. ""Jahangir"" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > I am stuck at a wierd problem. I am trying to do comparision between a > "query string" and a "string value". the string consists of some > diacriticals and single quotes. > But when i try to escape the single quotes using backshash (\) it doesnt > work. and when i try to use it inside a double quote preg_replace() doesnt > recognise the code. > why is php not comaparing string with single quotes?? > > here is the code: > if($_GET['query']==new) > { filter($query);} > elseif($_GET['query']==some'u'all) > { filter($query);} > elseif($_GET['query']==all'u'ppl) > { filter($query);} > > function filter($query) > { > $pattern = array ('/new/','/some'u'all/','/all'u'ppl/'); > $rep = array ("new way","Some of you all ","all of you"); > $op = preg_replace($pattern,$rep,$_GET['query']); > echo "new value $op"; > } > > > also i wanted to just clarify is there a way of using multiple OR's in the > same "if" condition > i.e if(($_GET['query]')==new||newday||newtime||newbeginning||newthing) > { > // fn here; > } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Downloading utf-8 encoded files
Hi Try this: There shouldn't be a character encoding problem with this two lines. Don't forget the mime type: http://earth.google.com/support/bin/answer.py?answer=25094&topic=1139 bernhard Am Dienstag, den 26.12.2006, 17:22 +0500 schrieb Fahad Pervaiz: > I want to download UTF-8 encoded kml files from a website. I have written a > script that automatically downloads KML file. Problem is that some of the > utf-8 charc are distrubed after saving file on windows. below is the script. > > > . > . > . > >$handle = fopen($link, "rb"); > >$handle2= fopen("kml/$i.kml","w"); > >$contents = ''; >while (!feof($handle)) { > $contents = fread($handle, 8192); > fwrite($handle2, $contents); >} >fclose($handle); >fclose($handle2); > . > . > . > . > > Also, there is another problem.Downloading file using the above script, > downloads incomplete file, means some of the information is skipped and file > size is also small. > > Help would be appriciated > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: pattern containing single quote in IF statement
First of all, I strongly feel that you should have double quotes around the string you like to compare with (e.g. "new"). Otherwise, you are comparing against a string but to something else (integer ?). Without quotes, PHP will throw an error (not sure if it will throw a fatal error or something else). Second, do a var_dump on $_GET ['query']. What do you get? (white space before, after the string? encodes quotes?) You may also look at the function strcasecmp, which is little more elegant than your solution, in my opinion. Regarding your question about "multiple OR", I would do something like: $things_to_look_for = array ( "new, "newday" ... and so on); if ( in_array ( $_GET['query'], $things_to_look_for ) ) { // do some stuff } /frank 26 dec 2006 kl. 14.42 skrev Jahangir: I tried that also but it didnt work. if($_GET['query']=="some'u'all") { filter($query);} I still get the same error. ""Jahangir"" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] I am stuck at a wierd problem. I am trying to do comparision between a "query string" and a "string value". the string consists of some diacriticals and single quotes. But when i try to escape the single quotes using backshash (\) it doesnt work. and when i try to use it inside a double quote preg_replace () doesnt recognise the code. why is php not comaparing string with single quotes?? here is the code: if($_GET['query']==new) { filter($query);} elseif($_GET['query']==some'u'all) { filter($query);} elseif($_GET['query']==all'u'ppl) { filter($query);} function filter($query) { $pattern = array ('/new/','/some'u'all/','/all'u'ppl/'); $rep = array ("new way","Some of you all ","all of you"); $op = preg_replace($pattern,$rep,$_GET['query']); echo "new value $op"; } also i wanted to just clarify is there a way of using multiple OR's in the same "if" condition i.e if(($_GET['query]')==new||newday||newtime||newbeginning|| newthing) { // fn here; } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php