Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Sep 2004
    Posts
    47
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Cannot get correct output, trouble with quotes (newbie)

    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:

    PHP Code:
    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:

    Code:
    <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.

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

    PHP Code:
    href="javascript:searchKeyword(/'' . $word .  '/')" 
    PHP Code:
    href="javascript:searchKeyword(/"' . $word .  '/")" 
    PHP Code:
    href="javascript:searchKeyword(&quo;' . $word .  '&quo;)" 
    Any help would be greatly appreciated. I apologize if this is a dumb question.

  • #2
    Senior Coder
    Join Date
    Aug 2003
    Location
    One step ahead of you.
    Posts
    2,815
    Thanks
    0
    Thanked 3 Times in 3 Posts
    You were really close. You escape characters with the backslash.
    PHP Code:
    echo ' <span style="font-size: ' $size '%;"> 
                                     
    <acronym title="This keyword occurs ' 
    $count ' times."> 
    <a href="javascript:searchKeyword(\'' 
    $word .  '\')">' $word '</a> 
    </acronym></span> '

    I'm not sure if this was any help, but I hope it didn't make you stupider.

    Experience is something you get just after you really need it.
    PHP Installation Guide Feedback welcome.

  • #3
    Regular Coder
    Join Date
    Mar 2006
    Location
    Germany
    Posts
    279
    Thanks
    0
    Thanked 0 Times in 0 Posts
    PHP Code:
    <?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)

  • #4
    New Coder
    Join Date
    Sep 2004
    Posts
    47
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks dude.

  • #5
    Senior Coder
    Join Date
    Nov 2002
    Location
    North-East, UK
    Posts
    1,265
    Thanks
    0
    Thanked 0 Times in 0 Posts
    If you prefer using HTML then breakout of the PHP

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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •