php-general Digest 27 Dec 2006 09:25:48 -0000 Issue 4536

Topics (messages 246222 through 246230):

Re: calling a function in the same page
        246222 by: Aras
        246225 by: Peter Lauri

Downloading utf-8 encoded files
        246223 by: Fahad Pervaiz
        246228 by: Bernhard Zwischenbrugger

pattern containing single quote in IF statement
        246224 by: Jahangir
        246226 by: Peter Lauri
        246227 by: Jahangir
        246229 by: Frank Arensmeier

GD 2.0.28 + PHP 4.4.2 + pixelation :(
        246230 by: Steven Macintyre

Administrivia:

To subscribe to the digest, e-mail:
        [EMAIL PROTECTED]

To unsubscribe from the digest, e-mail:
        [EMAIL PROTECTED]

To post to the list, e-mail:
        [email protected]


----------------------------------------------------------------------
--- Begin Message ---

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: [email protected]
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 "<br><br><a href=\"isearch($query)\">More results from Mysite</a>";
// 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 "<br>NO RESULTS TO DISPLAY"; }

echo "<tr>"; echo "<h4 style=\"color:#FF0000\" align=\"center\">Results from
Mysite</h4>";

for($i=0;$i<$count;$i++)

{ echo '<pre>';

$no=$i+1;

$url=$phpobj["ResultSet"]["Result"]["$i"]["Url"];

echo "<h3>" ."$no. ". "<a href=\"$url\">" .
$phpobj["ResultSet"]["Result"]["$i"]["Title"] . "</a></h3>"; echo "</tr>";

echo "<tr>"; echo $phpobj["ResultSet"]["Result"]["$i"]["Summary"]; echo
"</tr>";

echo "<br>"; echo "<tr>"; echo "<b>"
.$phpobj["ResultSet"]["Result"]["$i"]["Url"] ."</b>"; echo "</tr>";

echo "<br>"; $link=$phpobj["ResultSet"]["Result"]["$i"]["DisplayUrl"];

echo "<tr>"; echo "<a href=\"$url\">$link</a>"; echo "</tr>";

echo '</pre>'; }}



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

--- End Message ---
--- Begin Message ---
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 <head> tag of the
HTML that you generate. Also you would need to download the Prototype
library and include them in <head> 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 "<br><br><a href=\"javascript:doSearch($query)\">More results from
Mysite</a>";
echo "<div id='resultsdiv'></div>";
------



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: [email protected]
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: [email protected]
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 "<br><br><a href=\"isearch($query)\">More results from Mysite</a>";
// 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 "<br>NO RESULTS TO DISPLAY"; }

echo "<tr>"; echo "<h4 style=\"color:#FF0000\" align=\"center\">Results from
Mysite</h4>";

for($i=0;$i<$count;$i++)

{ echo '<pre>';

$no=$i+1;

$url=$phpobj["ResultSet"]["Result"]["$i"]["Url"];

echo "<h3>" ."$no. ". "<a href=\"$url\">" .
$phpobj["ResultSet"]["Result"]["$i"]["Title"] . "</a></h3>"; echo "</tr>";

echo "<tr>"; echo $phpobj["ResultSet"]["Result"]["$i"]["Summary"]; echo
"</tr>";

echo "<br>"; echo "<tr>"; echo "<b>"
.$phpobj["ResultSet"]["Result"]["$i"]["Url"] ."</b>"; echo "</tr>";

echo "<br>"; $link=$phpobj["ResultSet"]["Result"]["$i"]["DisplayUrl"];

echo "<tr>"; echo "<a href=\"$url\">$link</a>"; echo "</tr>";

echo '</pre>'; }}



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

--- End Message ---
--- Begin Message ---
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

--- End Message ---
--- Begin Message ---
Hi

Try this:
<?php
...
$contents=file_get_contents($link);
file_put_contents("kml/$.kml",$contents)
?>

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
> 

--- End Message ---
--- Begin Message ---
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 "<br>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;
}

--- End Message ---
--- Begin Message ---
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

--- End Message ---
--- Begin Message ---
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 "<br>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;
> }

--- End Message ---
--- Begin Message --- 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 "<br>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


--- End Message ---
--- Begin Message ---
Hi All,

I have done some searching via google and some answers say change
copyimageresampled to copyimageresized etc 

I have tried all fixes ... to no avail


I have one image here 1280 x 960 (150 dpi) 24 depth

When using the following it pixelates ... 

function createthumb($name,$filename,$new_w,$new_h)
{
        $system=explode(".",$name);
        $src_img=imagecreatefromjpeg($name);
        $old_x=imageSX($src_img);
        $old_y=imageSY($src_img);
        if ($old_x > $old_y)
        {
                $thumb_w=$new_w;
                $thumb_h=$old_y*($new_h/$old_x);
        }
        if ($old_x < $old_y)
        {
                $thumb_w=$old_x*($new_w/$old_y);
                $thumb_h=$new_h;
        }
        if ($old_x == $old_y)
        {
                $thumb_w=$new_w;
                $thumb_h=$new_h;
        }
        $dst_img=ImageCreateTrueColor($thumb_w,$thumb_h);
        
imagecopyresized($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y);
        imagejpeg($dst_img,$filename);
        imagedestroy($dst_img);
        imagedestroy($src_img);
}

Which I am of course calling with
createthumb($add,'../pics/'.$largeval,350,263);

Now ... afaik my new sizes are proportional to the big ones ... but it
pixelates :(

However,

Using an image 1600 x 1200 (96 dpi) 24 depth it works and there is no
pixilation

Can someone perhaps assist now?


                                                          
Kind Regards,


Steven Macintyre
http://steven.macintyre.name
--

http://www.friends4friends.co.za

--- End Message ---

Reply via email to