How to add < href to PHP?

by 2 replies
3
Hi to all,
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 LINK GOES HERE text ".$data[1]["Category"]["name"]." text text text");

I added: "LINK GOES HERE" beacuse i 'm not allowed to post links

But when i add the link,my site collapse
Can you please help me with that?
#programming #< #add #href #php
  • The code you have there looks for ['!LOCATION'] and if it finds that text it replaces it with the value in the $data[2]["Location"]["name"]

    please explain "my site collapse"

    If its a fixed link that doesn't change im guessing that your issue is probably non-escaped quotes.

    the " are stuffing things up because <a href="link to someoehrere">the link</a> has quotes in it.

    Try using single quotes ' or escaping them with a backslash (depending on what language it is)
    <a href=\"link to someoehrere\">the link</a>
  • Yes. There are many ways. One of them is:

    <html>
    <?php
    echo '<b>' . htmlspecialchars( $name ) . '</b>,<br />';
    echo 'Sorry there's a problem sending your message. ';
    echo 'Please <a href="/mail.html">try again</a>.';
    ?>
    </html>

    another:

    <html>
    <b><?php htmlspecialchars( $name ); ?></b>,<br />
    Sorry there's a problem sending your message.
    Please <a href="/mail.html">try again</a>.
    </html>

Next Topics on Trending Feed

  • 3

    Hi to all, 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");