php-general Digest 25 Dec 2006 08:04:24 -0000 Issue 4533

Topics (messages 246195 through 246204):

calling a function in the same page
        246195 by: Jahangir
        246196 by: Jahangir
        246204 by: Jahangir

Counting the occurences of items in an array
        246197 by: Dotan Cohen
        246198 by: Sumeet
        246199 by: Myron Turner
        246200 by: tedd
        246201 by: Dotan Cohen

Odd behavior
        246202 by: jekillen

New ImageMagick Extension
        246203 by: Kevin Waterson

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:
        php-general@lists.php.net


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

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

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

--- End Message ---
--- Begin Message ---
Has this wheel been invented, but simpler? I've an array of words that
I'd like to know how many occurences of each there are. For instance:
$fruits = array(
   "lemon",
   "orange",
   "banana",
   "apple",
   "orange",
   "banana",
   "orange"    );

And I'd like to create this:
$fruit_count = array(
   "lemon" => 1,
   "orange" => 3,
   "banana" => 2,
   "apple" => 1    );

My current plan of action is to create $fruit_count, and check if
$fruits[0] is listed in it. If not, then I'll add it with a value of
1. If it is already listed then I'll just increase it's number. Ditto
for $fruits[1] and so on...

Has someone cleverer than myself found a better way of doing this?
This function will be used as a word count for text documents, and
some of them have over 5000 words. So if there's a better way of doing
this I'd love to know. Thanks.

Dotan Cohen

http://what-is-what.com/what_is/html_email.html
http://lyricslist.com/lyrics/artist_albums/162/disturbed.php

--- End Message ---
--- Begin Message ---
Dotan Cohen wrote:
Has this wheel been invented, but simpler? I've an array of words that
I'd like to know how many occurences of each there are. For instance:
$fruits = array(
   "lemon",
   "orange",
   "banana",
   "apple",
   "orange",
   "banana",
   "orange"    );

And I'd like to create this:
$fruit_count = array(
   "lemon" => 1,
   "orange" => 3,
   "banana" => 2,
   "apple" => 1    );


check
http://in2.php.net/manual/en/function.array-count-values.php



--
Thanking You

Sumeet Shroff
http://www.prateeksha.com
Web Designers and PHP / Mysql Ecommerce Development, Mumbai India

--- End Message ---
--- Begin Message ---
From the manual:

array array_count_values ( array input)

array_count_values() returns an array using the values of the input array as keys and their frequency in input as values.

Example 1. array_count_values() example
<?php
$array = array(1, "hello", 1, "world", "hello");
print_r(array_count_values($array));
?>

The printout of the above program will be:

Array
(
    [1] => 2
    [hello] => 2
    [world] => 1
)

Dotan Cohen wrote:
Has this wheel been invented, but simpler? I've an array of words that
I'd like to know how many occurences of each there are. For instance:
$fruits = array(
   "lemon",
   "orange",
   "banana",
   "apple",
   "orange",
   "banana",
   "orange"    );

And I'd like to create this:
$fruit_count = array(
   "lemon" => 1,
   "orange" => 3,
   "banana" => 2,
   "apple" => 1    );

My current plan of action is to create $fruit_count, and check if
$fruits[0] is listed in it. If not, then I'll add it with a value of
1. If it is already listed then I'll just increase it's number. Ditto
for $fruits[1] and so on...

Has someone cleverer than myself found a better way of doing this?
This function will be used as a word count for text documents, and
some of them have over 5000 words. So if there's a better way of doing
this I'd love to know. Thanks.

Dotan Cohen

http://what-is-what.com/what_is/html_email.html
http://lyricslist.com/lyrics/artist_albums/162/disturbed.php


--

_____________________
Myron Turner
http://www.room535.org
http://www.bstatzero.org
http://www.mturner.org/XML_PullParser/

--- End Message ---
--- Begin Message ---
At 8:35 PM +0200 12/24/06, Dotan Cohen wrote:
Has this wheel been invented, but simpler? I've an array of words that
I'd like to know how many occurences of each there are. For instance:
$fruits = array(
   "lemon",
   "orange",
   "banana",
   "apple",
   "orange",
   "banana",
   "orange"    );

And I'd like to create this:
$fruit_count = array(
   "lemon" => 1,
   "orange" => 3,
   "banana" => 2,
   "apple" => 1    );

My current plan of action is to create $fruit_count, and check if
$fruits[0] is listed in it. If not, then I'll add it with a value of
1. If it is already listed then I'll just increase it's number. Ditto
for $fruits[1] and so on...

Has someone cleverer than myself found a better way of doing this?
This function will be used as a word count for text documents, and
some of them have over 5000 words. So if there's a better way of doing
this I'd love to know. Thanks.

Dotan Cohen

Dotan:

array_count_values()

tedd
--
-------
http://sperling.com  http://ancientstones.com  http://earthstones.com

--- End Message ---
--- Begin Message ---
Thanks for the link to the function. Know that I did RTFM before
posting, but I missed that one.

Dotan Cohen

http://lyricslist.com/lyrics/artist_albums/219/xyz.php
http://simplesniff.com

--- End Message ---
--- Begin Message ---
Hello,
Am having trouble with some code.
I have been developing a web based application on
a machine running php v4.3x, Apache 1.3x Mac OSX 10.3
The application works as expected on this machine.
So I copied the code to my server which is running FreeBSD
v6.0, Apache 1.3.34, php v5.1.2.
On this machine the exact same code does not work as expected
in some critical places.
Here is the code suspect of being troublesome:

include("process.php");
if(file_exists("in_tmp.php"))
  {
   include("in_tmp.php");
  }
if(file_exists("out_tmp.php"))
  {
   include("out_tmp.php");
  }
if(file_exists("save_tmp.php"))
  {
   include("save_tmp.php");
  }
if(file_exists("request_tmp.php"))
  {
   include("request_tmp.php");
  }

< code snipped>

function display($list, $in, $out, $save, $req, $x)
 {
   switch($list)
    {
      case 'in':
      for($i = 0; $i < count($in); $i++)
      {$j = $i + 1;
print "<a href=\"steps.php?list=$list&next=$j&x=$x\">$j</a><br><br>";
      // two sets of links displayed instead of one
       };
        break;
        case 'out':
         for($i = 0; $i < count($out); $i++)
          {$j = $i + 1;
print "<a href=\"steps.php?list=$list&next=$j&x=$x\">$j</a><br><br>";
            // two sets of links displayed instead of one
            };
         break;
         case 'save':
          for($i = 0; $i < count($save); $i++)
           {$j = $i + 1;
print "<a href=\"steps.php?list=$list&next=$j&x=$x\">$j</a><br><br>";
             // two sets of links displayed instead of one
            };
          break;
          case 'requests':
          for($i = 0; $i < count($req); $i++)
           {$j = $i + 1;
print "<a href=\"steps.php?list=$list&next=$j&x=$x\">$j</a><br><br>";
             // two sets of links displayed instead of one
           };
          break;
          };
      }
The print lines above are supposed to produce a list of links to files.
In the web display I get duplicate sets of links which seems to mean
that the loops in the function are running twice, and in one instance
three times instead of once. The arrays are taken from the included
files. These files are php scripts produced by a php script after a
directory is opened and read. The arrays a declared and initialized
in these scripts. If there are no files in the directories, the scripts are
not written (thus the code if(file_exists(so and so file) etc..).
Is there a difference in the behavior of include between php 4x and 5x?
I am also having problems with a regular expression:

$w = ereg("To:&nbsp;&nbsp;&nbsp;&nbsp;\n([ A-Za-z]*)", $data, $m);
$x = ereg("<recipient who='".$m[1]."' to='(.*)' />", $rout, $m_1);
 $dest = $m_1[1];

This code has opened and read a file and is picking out data from the file so it can use this data to copy the file to another directory. On my dev server this code works fine. On the production server this code will not pick up the
match from the first regex and so will not find a match in the second.

Is this a difference between versions of php, known bugs, possibly a
problem with the php or Apache installation on my production server?
If nothing comes to anyone's mind, I will have to do some digging.
but if there is I would appreciate suggestions advice.
Thanks in advance.
JK

--- End Message ---
--- Begin Message ---
Just what all long suffering image folks have been needing

http://phpro.org/phpdev/New-ImageMagick-Extension.html

When finished, this should be alot of fun.

K

--- End Message ---

Reply via email to