简体   繁体   中英

how to use single quotes inside quotes in php html

i have an php html code below

<div   class="btn form-bttn1" style="width:auto; float:right;"><a href=<?php if($rowHO->hotel_booking_type==2){$checkin=date('Y-m-d',strtotime($check_in)); 
                                   $checkout=date('Y-m-d',strtotime($check_out)); ?>"https://secure.booking.com/book.html?aid=870045&hostname=www.safarion.com&stage=1&checkin=<?php echo $checkin; ?>&checkout=<?php echo $checkout; ?>&maxrooms=1&hotel_id=<?php echo $rowHO->hotel_hotels_id; ?>" target=_blank<?php }else{ ?>"javascript:submitform(myForm,<?php echo $rowHO->hotel_id; ?>,'<?php echo $rowHO->hotel_name; ?>')"
                              <?php } ?>>Choose your room </a></div>





javascript:submitform(myForm,<?php echo $rowHO->hotel_id; ?>,'<?php echo $rowHO->hotel_name; ?>')

here hotel_name containes a single quote.

and thus display an error

Uncaught SyntaxError: missing ) after argument list

submitform(myForm,79,Radisson's Blu Resort Temple Bay)

Use backslash, eg:

<?php
       echo '\'';  //Output will be ' ;
 // OR
       echo "\"";  //Output will be "" ;
?>

Use addslashes to escape charecter

$hotel_name = "Hotel O'Broy!";

// Outputs: Hotel O\'Broy!

echo addslashes($hotel_name );

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