简体   繁体   中英

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'>

,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?

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."\">"; ?>">

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.'">'; ?>">

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM