Page 1 of 1
Very Weird Error
Posted: Wed Sep 07, 2005 5:03 am
by Ree
When I use this
Code: Select all
$replacer->ReplaceGlobalValue('ItemValue', "<?php echo $row['headline']; ?>");
I get this
Code: Select all
Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in C:\Software\Apache2\htdocs\inter\replacer\definers\replace_del_news.php on line 7
How come? I have singe quotes between double ones.
Re: Very Weird Error
Posted: Wed Sep 07, 2005 5:15 am
by Roja
Ree wrote:
How come? I have singe quotes between double ones.
Cause you are already in php mode at the beginning of the line. It should be:
Code: Select all
$replacer->ReplaceGlobalValue('ItemValue', $row['headline']);
Re: Very Weird Error
Posted: Wed Sep 07, 2005 5:18 am
by Ree
Roja wrote:Ree wrote:
How come? I have singe quotes between double ones.
Cause you are already in php mode at the beginning of the line.
hahaha

. no, I need the string to be "<?php echo $row['headline']; ?>". I want to pass the string, not the value of $row['headline'].
Posted: Wed Sep 07, 2005 6:30 am
by CoderGoblin
Try using single quotes...
Code: Select all
$replace=$replacer->ReplaceGlobalValue('ItemValue', '<?php echo $row["headline"]; ?>');
Double quotes allow variables to be replaced with their values so the $row['headline'] is probably causing the error.
Hope that solves it.
Posted: Wed Sep 07, 2005 6:47 am
by Ree
Yes, I had this solution in mind as well and now the string gets passed, but is it ok to use double quotes when retrieving an array element? I've always used single quotes for string keys and no quotes for numeric keys.
Posted: Wed Sep 07, 2005 7:08 am
by CoderGoblin
Convention is to always use single quotes for arrays but I think it is an acceptable exception in this case to make the thing more readable without having to concatenate different things.
Code: Select all
$replace=$replacer->ReplaceGlobalValue('ItemValue', '<?php echo $row['."'"headline'".']; ?>');
is

Posted: Wed Sep 07, 2005 9:17 am
by infolock
I think you have misunderstood him coder. While your method may be correct (although I'm not sure, never really tried it that way... ?), I think he was meaning something like this :
Code: Select all
//Double Quotes Array for $row
$replace=$replacer->ReplaceGlobalValue('ItemValue', '<?php echo $row["headline"]; ?>');
//Single Quote Array for $row
$replace=$replacer->ReplaceGlobalValue('ItemValue', '<?php echo $row['headline']; ?>');
both are very valid and it's all about your choice of preference. It pretty much falls in the same like of echoing with single or double quotes. Both work the same except double quotes will allow you a little more control over the string should you decide you need to insert new line characters or the like.
Posted: Wed Sep 07, 2005 9:45 am
by CoderGoblin
//Single Quote Array for $row
$replace=$replacer->ReplaceGlobalValue('ItemValue', '<?php echo $row['headline']; ?>');
Will not work as you are closing the quoted string (guess T_STRING error). Bear in mind he wanted the string, not the value. Double quotes work for arrays although another solution would be to escape the $ with a backslash and use double quotes around the whole thing.
Code: Select all
$replace=$replacer->ReplaceGlobalValue('ItemValue', "<?php echo \$row['headline']; ?>");
Now why didn't I think of that before...

Posted: Wed Sep 07, 2005 10:43 am
by Ree
the things you explain work, yes. now i'm getting mad while trying to solve a more complex thing.
Code: Select all
echo '
<tr>
<td><a href="view_news.php?item=<?php echo $row['id']; ?>"><?php echo $row['headline']; ?></a></td>
<td class="padding_side"><?php echo $row['posted']; ?></td>
<td><input type="checkbox" name="item_array[]" value="<?php echo $row['id']; ?>" /></td>
</tr>
';
simply won't work. I've been trying to solve the same but without any luck. Any ideas on how to make the thing echo'able?
Posted: Wed Sep 07, 2005 10:46 am
by John Cartwright
infolock wrote:Code: Select all
//Single Quote Array for $row
$replace=$replacer->ReplaceGlobalValue('ItemValue', '<?php echo $row['headline']; ?>');
both are very valid and it's all about your choice of preference. It pretty much falls in the same like of echoing with single or double quotes. Both work the same except double quotes will allow you a little more control over the string should you decide you need to insert new line characters or the like.
Actually that one is not valid, you forgot to escape your single quotes
Code: Select all
//Single Quote Array for $row
$replace=$replacer->ReplaceGlobalValue('ItemValue', '<?php echo $row[\'headline\']; ?>');
Ree wrote:the things you explain work, yes. now i'm getting mad while trying to solve a more complex thing.
Code: Select all
echo '
<tr>
<td><a href="view_news.php?item=<?php echo $row['id']; ?>"><?php echo $row['headline']; ?></a></td>
<td class="padding_side"><?php echo $row['posted']; ?></td>
<td><input type="checkbox" name="item_array[]" value="<?php echo $row['id']; ?>" /></td>
</tr>
';
simply won't work. I've been trying to solve the same but without any luck. Any ideas on how to make the thing echo'able?
Read my reply to infolock
Posted: Wed Sep 07, 2005 2:40 pm
by Ree
Really, I cannot get this echoed properly. I tried escaping quotes, but then I get no values that should be there.
Code: Select all
echo '
<tr>
<td><a href="view_news.php?item=$row['id']">$row['headline']</a></td>
<td class="padding_side">$row['posted']</td>
<td><input type="checkbox" name="item_array[]" value="$row['id']" /></td>
</tr>
';
I really need some help here, how can I make the above echoed properly (properly I mean values of $row array printed)? Escaping like this
prevents outputting the values.
Posted: Wed Sep 07, 2005 2:44 pm
by feyd
Code: Select all
echo '
<tr>
<td><a href="view_news.php?item='.$row['id'].'">'.$row['headline'].'</a></td>
<td class="padding_side">'.$row['posted'].'</td>
<td><input type="checkbox" name="item_array[]" value="'.$row['id'].'" /></td>
</tr>
';
or
Code: Select all
echo <<<STOP
<tr>
<td><a href="view_news.php?item={$row['id']}">{$row['headline']}</a></td>
<td class="padding_side">{$row['posted']}</td>
<td><input type="checkbox" name="item_array[]" value="{$row['id']}" /></td>
</tr>
STOP;
Posted: Wed Sep 07, 2005 4:09 pm
by Ree
Finally got it working. Thanks for ideas
