[PHP] Str_Replace Command

2004-02-02 Thread Christopher J. Crane
I have never had this problem before and it is probably something simple...
Please take a look at the two foreach statements. I am at a loss as to why
the second line does not actually remove the quotes. The first foreach
statement does so how are they different.

  $StockURL =
http://finance.yahoo.com/d/quotes.txt?s=xrx,ikn,dankyf=sl1e=.txt;;
  $StockResults = implode('', file($StockURL));
  $Rows = split(\n, $StockResults);
  foreach($Rows as $Row) { echo str_replace('',,$Row).br\n; }
  foreach($Rows as $Row) { str_replace('',,$Row); echo $Row.br\n; }

Eventually, I need to break apart the $Row into two elements $Symbol and
$Price and then into a two dimensional array. I have done this with the code
below, but so far, I can not get rid of the quotes.

  foreach($Rows as $Row){
list($Symbol, $Price) = split(\n, $Row);
$TickerData=array($Symbol=$Price);
}

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Str_Replace Command

2004-02-02 Thread Jason Wong
On Tuesday 03 February 2004 00:14, Christopher J. Crane wrote:

   $StockURL =
 http://finance.yahoo.com/d/quotes.txt?s=xrx,ikn,dankyf=sl1e=.txt;;
   $StockResults = implode('', file($StockURL));
   $Rows = split(\n, $StockResults);
   foreach($Rows as $Row) { echo str_replace('',,$Row).br\n; }
   foreach($Rows as $Row) { str_replace('',,$Row); echo $Row.br\n; }

str_replace() RETURNS the replaced string. It does not alter $Row.

-- 
Jason Wong - Gremlins Associates - www.gremlins.biz
Open Source Software Systems Integrators
* Web Design  Hosting * Internet  Intranet Applications Development *
--
Search the list archives before you post
http://marc.theaimsgroup.com/?l=php-general
--
/*
Spiritual leadership should remain spiritual leadership and the temporal
power should not become too important in any church.
- Eleanor Roosevelt
*/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Str_Replace Command

2004-02-02 Thread Christopher J. Crane
Ok I got around it by the following, but now I have a new problem. I can not
get the two dimensional array working. I want to later be able to output a
variable like this $TickerData[IKN] and it will output the associated
$Price.

  $StockURL =
http://finance.yahoo.com/d/quotes.txt?s=xrx,ikn,dankyf=sl1e=.txt;;
  $StockResults = implode('', file($StockURL));
  $Rows = split(\n, $StockResults);
  foreach($Rows as $Row) {
list($Symbol, $Price) = split(,, $Row);
   $Symbol = str_replace('', , $Symbol);
   $TickerData = array($Symbol=$Ticker);
}
  print_r($TickerData);
  echo $TickerData[IKN].br\n;




Jason Wong [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 On Tuesday 03 February 2004 00:14, Christopher J. Crane wrote:

$StockURL =
  http://finance.yahoo.com/d/quotes.txt?s=xrx,ikn,dankyf=sl1e=.txt;;
$StockResults = implode('', file($StockURL));
$Rows = split(\n, $StockResults);
foreach($Rows as $Row) { echo str_replace('',,$Row).br\n; }
foreach($Rows as $Row) { str_replace('',,$Row); echo
$Row.br\n; }

 str_replace() RETURNS the replaced string. It does not alter $Row.

 -- 
 Jason Wong - Gremlins Associates - www.gremlins.biz
 Open Source Software Systems Integrators
 * Web Design  Hosting * Internet  Intranet Applications Development *
 --
 Search the list archives before you post
 http://marc.theaimsgroup.com/?l=php-general
 --
 /*
 Spiritual leadership should remain spiritual leadership and the temporal
 power should not become too important in any church.
 - Eleanor Roosevelt
 */

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Str_Replace Command

2004-02-02 Thread Jason Wong
On Tuesday 03 February 2004 00:52, Christopher J. Crane wrote:
 Ok I got around it by the following, but now I have a new problem. I can
 not get the two dimensional array working. I want to later be able to
 output a variable like this $TickerData[IKN] and it will output the
 associated $Price.

   print_r($TickerData);

So what does the above show? If it isn't what you expect, figure out *why*. 
Like how is $TickerData being assigned.

-- 
Jason Wong - Gremlins Associates - www.gremlins.biz
Open Source Software Systems Integrators
* Web Design  Hosting * Internet  Intranet Applications Development *
--
Search the list archives before you post
http://marc.theaimsgroup.com/?l=php-general
--
/*
We have phasers, I vote we blast 'em!
-- Bailey, The Corbomite Maneuver, stardate 1514.2
*/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Str_Replace Command

2004-02-02 Thread Christopher J. Crane
Well this is it and it is really got me...
Echoing out the $Symbol and $Price works just fine one row about the
$TickerData array assignment. Yet it outputs nothing.
Array ( [] = ) is what I get. If I change the line to
$TickerData = array ($Symbol = $Price); I get nothing, or the same
result. If I change the line to
$TickerData = array ('$Symbo'l = '$Price'); I get the following
Array ( [$Symbol] = $Price ) which tells me the assignment works, but it
seems like the $Symbol and $Price variable are blank when assigning to the
array. I know that they are not blank since they echoed out just fine one
line above.GRR



  $StockURL =
http://finance.yahoo.com/d/quotes.txt?s=xrx,ikn,dankyf=sl1e=.txt;;
  $StockResults = implode('', file($StockURL));
  $Rows = split(\n, $StockResults);
  foreach($Rows as $Row) {
list($Symbol, $Price) = split(,, $Row);
 $Symbol = str_replace('', , $Symbol);
echo $Symbol. - .$Price.br\n;
$TickerData = array ($Symbol = $Price);
}
  print_r($TickerData);



Jason Wong [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 On Tuesday 03 February 2004 00:52, Christopher J. Crane wrote:
  Ok I got around it by the following, but now I have a new problem. I can
  not get the two dimensional array working. I want to later be able to
  output a variable like this $TickerData[IKN] and it will output the
  associated $Price.

print_r($TickerData);

 So what does the above show? If it isn't what you expect, figure out
*why*.
 Like how is $TickerData being assigned.

 -- 
 Jason Wong - Gremlins Associates - www.gremlins.biz
 Open Source Software Systems Integrators
 * Web Design  Hosting * Internet  Intranet Applications Development *
 --
 Search the list archives before you post
 http://marc.theaimsgroup.com/?l=php-general
 --
 /*
 We have phasers, I vote we blast 'em!
 -- Bailey, The Corbomite Maneuver, stardate 1514.2
 */

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Str_Replace Command

2004-02-02 Thread Jason Wong
On Tuesday 03 February 2004 01:09, Christopher J. Crane wrote:
 Well this is it and it is really got me...
 Echoing out the $Symbol and $Price works just fine one row about the
 $TickerData array assignment. Yet it outputs nothing.
 Array ( [] = ) is what I get. If I change the line to
 $TickerData = array ($Symbol = $Price); I get nothing, or the same
 result. If I change the line to
 $TickerData = array ('$Symbo'l = '$Price'); I get the following
 Array ( [$Symbol] = $Price ) which tells me the assignment works, but it
 seems like the $Symbol and $Price variable are blank when assigning to the
 array. I know that they are not blank since they echoed out just fine one
 line above.GRR

Are you sure that the line: echo $Symbol ...
is displaying something sensible for each $Row?

You're overwriting $TickerData at each iteration of the foreach-loop thus if 
your last $Row doesn't contain something sensible neither would $TickerData.

You probably want to use this assignment instead:

  $TickerData[$Symbol] = $Price;

-- 
Jason Wong - Gremlins Associates - www.gremlins.biz
Open Source Software Systems Integrators
* Web Design  Hosting * Internet  Intranet Applications Development *
--
Search the list archives before you post
http://marc.theaimsgroup.com/?l=php-general
--
/*
TANSTAAFL
*/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Str_Replace Command

2004-02-02 Thread Matt Matijevich
snip
  $StockURL =
http://finance.yahoo.com/d/quotes.txt?s=xrx,ikn,dankyf=sl1e=.txt;;
  $StockResults = implode('', file($StockURL));
  $Rows = split(\n, $StockResults);
  foreach($Rows as $Row) {
list($Symbol, $Price) = split(,, $Row);
 $Symbol = str_replace('', , $Symbol);
echo $Symbol. - .$Price.br\n;
$TickerData = array ($Symbol = $Price);
}
  print_r($TickerData);
/snip

why not replace:
$TickerData = array ($Symbol = $Price);

that line reassigns $TickerData to a array with one element in it
everytime you call it.  The last time through your loop, $Symbol = ''
and $Price = '', so you get Array ( [] = ) when you print_r

with this:
$TickerData[$Symbol] = $Price;

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Str_Replace Command

2004-02-02 Thread Crane, Christopher
Matt:
This worked perfect. Thank you. I didn't realize it was reassigning, I
thought it would work similar to array_push and add to the existing data. I
get it now, thanks to you.

Thanks again. I had been so frustrated I was losing my objectivity. 


Christopher J. Crane 
Network Manager - Infrastructure Services 
IKON Document Efficiency at Work 



-Original Message-
From: Matt Matijevich [mailto:[EMAIL PROTECTED] 
Sent: Monday, February 02, 2004 12:25 PM
To: [EMAIL PROTECTED]; [EMAIL PROTECTED]
Subject: Re: [PHP] Str_Replace Command

snip
  $StockURL =
http://finance.yahoo.com/d/quotes.txt?s=xrx,ikn,dankyf=sl1e=.txt;;
  $StockResults = implode('', file($StockURL));
  $Rows = split(\n, $StockResults);
  foreach($Rows as $Row) {
list($Symbol, $Price) = split(,, $Row);  $Symbol = str_replace('',
, $Symbol);
echo $Symbol. - .$Price.br\n;
$TickerData = array ($Symbol = $Price);
}
  print_r($TickerData);
/snip

why not replace:
$TickerData = array ($Symbol = $Price);

that line reassigns $TickerData to a array with one element in it everytime
you call it.  The last time through your loop, $Symbol = ''
and $Price = '', so you get Array ( [] = ) when you print_r

with this:
$TickerData[$Symbol] = $Price;

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php