How to add < href to PHP?

Discussion in 'PHP' started by nasi, Dec 1, 2011.

  1. #1
    Hi DP's,

    I need help with this line of code
    $data[1]["Category"]["body"] = str_replace("[!LOCATION!]", $data[2]["Location"]["name"], " ".$data[1]["Category"]["name"]." text text text ".$data[1]["Category"]["name"]." text text text");

    I want to add <href link to this line of code (where the "text" words are),so it shoud look something like this:

    $data[1]["Category"]["body"] = str_replace("[!LOCATION!]", $data[2]["Location"]["name"], " ".$data[1]["Category"]["name"]." text text <a href="http://www.example.com/">Home</a>text ".$data[1]["Category"]["name"]." text text text");

    But when i add the link,my site collapse
    Can you please help me with that?
     
    nasi, Dec 1, 2011 IP
  2. proactiv3

    proactiv3 Peon

    Messages:
    55
    Likes Received:
    7
    Best Answers:
    4
    Trophy Points:
    0
    #2
    $data[1]["Category"]["body"] = str_replace("[!LOCATION!]", $data[2]["Location"]["name"], " ".$data[1]["Category"]["name"]." text text <a href=\"http://www.example.com/\">Home</a>text ".$data[1]["Category"]["name"]." text text text");
    PHP:
    What a mess, lol.

    Anyway, the reason why it won't work is because you weren't escaping the " characters.

    "text text <a href=\"http://xxx.com/\">..."
    Code (markup):
    As you weren't doing so, the interpreter was assuming that the string was ending on the first " after the href and therefore would throw an invalid syntax error.
     
    proactiv3, Dec 1, 2011 IP
  3. nasi

    nasi Active Member

    Messages:
    135
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #3
    thanks so much proactiv3
    I love internet just because of people like you.You helping people for free just because you are great person.
    I'm seo expert,so if you need any help or advice on seo,be my guest - i will be glad to help
    thanks one more time
     
    nasi, Dec 1, 2011 IP
  4. NetStar

    NetStar Notable Member

    Messages:
    2,471
    Likes Received:
    541
    Best Answers:
    21
    Trophy Points:
    245
    #4
    The best programmers write logical human readable code. Rewrite that...
     
    NetStar, Dec 1, 2011 IP
  5. Spudster

    Spudster Peon

    Messages:
    96
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Ot you can

    <?php

    Php codes here

    ?> End PHP

    hfef... Your html here :)
     
    Spudster, Dec 1, 2011 IP
  6. nasi

    nasi Active Member

    Messages:
    135
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #6
    That was just an example text,also I'm not programmer
     
    nasi, Dec 1, 2011 IP
  7. kids

    kids Active Member

    Messages:
    411
    Likes Received:
    4
    Best Answers:
    2
    Trophy Points:
    68
    #7
    I get headache when read your question! :confused:
     
    kids, Dec 1, 2011 IP