...

View Full Version : Cannot get correct output, trouble with quotes (newbie)



jyoseph
03-15-2006, 07:39 PM
Hello, I usually stick to the CSS / HTML side of CodingForums and you'll soon see why.

I am making a minor mistake somewhere due to my lack of knowledge about php. I did some research and tried several different solutions. (Coming to the forums is usually my last effort after exhaustive research)

I am building a list of keywords.
Here is the part I am having difficulty with:


echo ' <span style="font-size: ' . $size . '%;">

<acronym title="This keyword occurs ' . $count . ' times.">
<a href="javascript:searchKeyword(' . $word . ')">' . $word . '</a>
</acronym></span> ';

Here is what I am getting:


<acronym title="This keyword occurs 1 times.">
<a href="javascript:searchKeyword(example_keyword)">example_keyword</a>
</acronym></span>

Here is what I need to get, I highlighted the difference.


<acronym title="This keyword occurs 1 times.">
<a href="javascript:searchKeyword('example_keyword')">example_keyword</a>
</acronym></span>

I have tried:


href="javascript:searchKeyword(/'' . $word . '/')"


href="javascript:searchKeyword(/"' . $word . '/")"


href="javascript:searchKeyword(&quo;' . $word . '&quo;)"

Any help would be greatly appreciated. I apologize if this is a dumb question.

marek_mar
03-15-2006, 07:43 PM
You were really close. You escape characters with the backslash.


echo ' <span style="font-size: ' . $size . '%;">

<acronym title="This keyword occurs ' . $count . ' times.">
<a href="javascript:searchKeyword(\'' . $word . '\')">' . $word . '</a>
</acronym></span> ';

ns1987
03-15-2006, 07:46 PM
<?php
echo ' <span style="font-size: ' . $size . '%;">

<acronym title="This keyword occurs ' . $count . ' times.">
<a href="javascript:searchKeyword(\'' . $word . '\')">' . $word . '</a>
</acronym></span> ';

?>

Works for me. Don't know why it didn't for you, or whether you did it incorrectly. (Didn't really compare closely)

jyoseph
03-15-2006, 07:51 PM
Thanks dude. :o

degsy
03-16-2006, 02:58 PM
If you prefer using HTML then breakout of the PHP



<?php
$url = 'http://www.google.com';
$name = 'Google';
?>
<a href="<?php echo $url; ?>"><?php echo $name; ?></a>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum