I'm confused with this, how to place a string in quotes?

Discussion in 'PHP' started by aandamar, Aug 24, 2011.

  1. #1
    It make me hurt, I can place a string(I don't know the name, it started with $) in quotes.

    by default, it looks like this:
    
    $name = 'aandamar';
    
    Code (markup):
    I want to make it like this
    
    $myname = 'aandamar';
    
    function showname {
    $name = '$myname';
    }
    
    Code (markup):
    my ig question, how I can export the $myname in showname function with the quotes?
    I try like above but can't see it works.
    hopefully there someone can help me out with this problem.

    thanks
     
    aandamar, Aug 24, 2011 IP
  2. iBank ™

    iBank ™ Peon

    Messages:
    63
    Likes Received:
    4
    Best Answers:
    1
    Trophy Points:
    0
    #2
    // #1
    $name = '"' . $name . '"';
    
    // #2
    $name = "\"$name\"";
    PHP:
    Choose the one that suits the best to you.
     
    iBank ™, Aug 24, 2011 IP
  3. aandamar

    aandamar Well-Known Member

    Messages:
    243
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    130
    Digital Goods:
    3
    #3
    Thanks mate,

    I've tried two codes above but can't see it works.
     
    aandamar, Aug 24, 2011 IP
  4. iBank ™

    iBank ™ Peon

    Messages:
    63
    Likes Received:
    4
    Best Answers:
    1
    Trophy Points:
    0
    #4
    <?php
    
    function showName($name)
    {
        echo "\"$name\"";
    }
    
    showName("Michael");
    
    ?>
    PHP:
    "Michael"
    Code (markup):
    What exactly does not work for you ?
     
    iBank ™, Aug 24, 2011 IP
  5. aandamar

    aandamar Well-Known Member

    Messages:
    243
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    130
    Digital Goods:
    3
    #5
    thanks mate for the help.

    this exactly the problem,

    the $problem is get the text from theme setting and then insert it on the rewrite.

    
    $problem = $mnl_settings['searchbase'];
    
    function ubah_searchbase() {
    	$GLOBALS['wp_rewrite']->search_base = '$problem';
    }
    
    Code (markup):
    by default, wp rewrite using normal text that is search.

    
    function ubah_searchbase() {
    	$GLOBALS['wp_rewrite']->search_base = 'search';
    }
    
    Code (markup):
    how I can add $problem in it?

    thanks
     
    aandamar, Aug 24, 2011 IP
  6. iBank ™

    iBank ™ Peon

    Messages:
    63
    Likes Received:
    4
    Best Answers:
    1
    Trophy Points:
    0
    #6
    $GLOBALS['wp_rewrite']->search_base = "$problem";
    PHP:
     
    iBank ™, Aug 24, 2011 IP
    aandamar likes this.
  7. aandamar

    aandamar Well-Known Member

    Messages:
    243
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    130
    Digital Goods:
    3
    #7
    it works, but giving other problem that make I can't sleep :(
    as you can see, on http://www.carownersmanualonline.com/, try to search something.
    the search base is go with the search term.
     
    aandamar, Aug 24, 2011 IP
  8. aandamar

    aandamar Well-Known Member

    Messages:
    243
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    130
    Digital Goods:
    3
    #8
    I get it works now mate!
    I'm so happy lol

    thanks!
     
    aandamar, Aug 24, 2011 IP
  9. iBank ™

    iBank ™ Peon

    Messages:
    63
    Likes Received:
    4
    Best Answers:
    1
    Trophy Points:
    0
    #9
    You are welcome! :)
     
    iBank ™, Aug 24, 2011 IP