Forum Moderators: coopster

Message Too Old, No Replies

how do i allow the character ' in my code?

         

marcus76

9:51 am on Mar 30, 2006 (gmt 0)

10+ Year Member



hi, i have the following piece of PHP which randomly displays a line of HTML.

I'm having a problem with the syntax when there is a ' mid way through the line. Can someone please help
me with the correct syntax.

<?php
// Random HTML Generator
// HTML Array....
$aHTML[0] = 'blah blah';
$aHTML[1] = 'blah blah blah';
$aHTML[2] = 'blah blah blah blah';
$aHTML[3] = 'blah blah's blah';
// Calculate index
$iUpper = sizeof($aHTML) - 1;
$iLower = 0;
$iIndex = rand($iLower, $iUpper);
// Display HTML
echo $aHTML[$iIndex];
?>

The line in question is:

$aHTML[3] = 'blah blah's blah';

I've tried variations of quotes - can't seem to get it to work.

Many thanks for your help in advance

Marc

scriptmasterdel

9:56 am on Mar 30, 2006 (gmt 0)

10+ Year Member



<?php
// Random HTML Generator
// HTML Array....
$aHTML[0] = 'blah blah';
$aHTML[1] = 'blah blah blah';
$aHTML[2] = 'blah blah blah blah';
$aHTML[3] = 'blah blah\'s blah';
// Calculate index
$iUpper = sizeof($aHTML) - 1;
$iLower = 0;
$iIndex = rand($iLower, $iUpper);
// Display HTML
echo stripcslashes($aHTML[$iIndex]);
?>

Add a backslash to the var and then stripslashes on the output!

Or use double quotes arount the array var

> $aHTML[3] = "blah blah's blah";

Hope this helps!

marcus76

10:26 am on Mar 30, 2006 (gmt 0)

10+ Year Member



scriptmasterdel,

many thanks for your post!

Regards

Marc

scriptmasterdel

10:32 am on Mar 30, 2006 (gmt 0)

10+ Year Member



No problem! Happy Programming ...