A much easier way to do this would be to use a temporary array and
then explode:
$tmp = array();
while($row = mysql_fetch_array($result)) // pulling stuff
from a database
{
$tmp[] = $row['category'];
}
$topic = explode('~',$tmp); // put the delimiter between
each entry
echo($topic); // this result is used in an AJAX script
No more worrying about whether the delimiter is the last character.
Ken
At 04:38 PM 12/21/2012, Tedd Sperling wrote:
Hi gang;
I just ran into something I have never had a problem with before.
Here's the code:
--- start of code
$topic = '';
while($row = mysql_fetch_array($result)) // pulling stuff
from a database
{
$topic .= $row['category'] . '~'; // adding a
delimiter between categories
}
$str_length = strlen($topic);
if($topic[$str_length-1] == '~')
{
$topic[$str_length-1] = ''; // remove last ~ delimiter
}
echo($topic); // this result is used in an AJAX script
--- end of code
Now, when the result is displayed (i.e., echoed) to Javascript
routines running in Safari and FireFox, everything is OK.
But when the result is displayed on IE, the "end" of the string
causes problems with the exact same javascript routine as used above.
Now, I realize that I have altered the string by removing the last
character and I have not shortened the string to reflect that, but I
never thought it would cause any problems.
Would someone please enlighten me as to why this would work in
Safari, FireFox, but not in IE?
Cheers,
tedd
PS: Also, please don't beg the answer by saying "It's IE -- what do
you expect?"
_____________________
tedd@xxxxxxxxxxxx
http://sperling.com
--
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