Hitesh Chauhan
Hitesh Chauhan

Reputation: 1082

Adding custom link to href tag

I am trying to add a custom link to the href tag using the following code

<input type="text" id="bootstrap_css_link_script" aria-hidden="true" 
 class="offscreen form-control" value="<?php echo "<link 
 href='".$bootstrap_css_link."'>"; ?>">

everything is fine but I want to get the href tag in doublequote("") as shown below

<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.0/css/bootstrap.min.css">

But after executing the above code I am getting the following result

<link href='//maxcdn.bootstrapcdn.com/bootstrap/3.3.0/css/bootstrap.min.css'>

Upvotes: 1

Views: 1781

Answers (3)

Ghanshyam Nakiya
Ghanshyam Nakiya

Reputation: 1712

You can do with single quotes of php

      <?php
        $bootstrap_css_link="//maxcdn.bootstrapcdn.com/bootstrap/3.3.0/css/bootstrap.min.css";
      ?>
      <input type="text" id="bootstrap_css_link_script" aria-hidden="true class="offscreen form-control" value="<?php echo '<link href="'.$bootstrap_css_link.'">'; ?>">

Upvotes: 0

silversunhunter
silversunhunter

Reputation: 1259

,Change to single quotes on the outside: Also, if the html attribute is double has a quote inside it needs to be escaped using: &quot;

<?php echo '<link href=&quot;'.$bootstrap_css_link.'&quot;>'; ?>

Also, you can remove echo to save a few clicks and clean up the code inside your HTML:

<?='<link href=&quot;'.$bootstrap_css_link.'&quot;>'?>

See this stack overflow question for reference: How to properly escape quotes inside html attributes?

Upvotes: 2

you have to use \" for escape a double quotes. So, your code should be like this

<input type="text" id="bootstrap_css_link_script" aria-hidden="true" 
 class="offscreen form-control" value="<?php echo "<link 
 href=\"".$bootstrap_css_link."\">"; ?>">

Upvotes: 2

Related Questions