echo in php javascript variable single and double quotes

375

I know that's the stupid question but i don't get code to work...i would like to echo this in php:

<img title="vlc" id="vlc-playlist" src="./img/vlc.png" onclick="window.location='vlc.php?user=test&pass=testpass&type=vlc'">

i im working with datatables jquery plugin so i need to put this img tag into $row[7].

my try to echo this is here:

$row[7] = '<img title="vlc" id="vlc-playlist" src="./img/vlc.png" onclick="window.location=vlc.php?user='.$row[1].'&pass='.$row[2].'&type=vlc">';

and i im getting this for output:

 <img title="vlc" id="vlc-playlist" src="./img/vlc.png" onclick="window.location=vlc.php?user=test&pass=testpass&type=vlc">

$row[1] = username $row[2] = password

so how to put single quotes to get result like on the first example?

Many Thanks.

593

Answer

Solution:

Escape the quote symbol with backslash:

$row[7] = '<img title="vlc" id="vlc-playlist" src="./img/vlc.png" onclick="window.location=\'vlc.php?user='.$row[1].'&pass='.$row[2].'&type=vlc\'">';

Single quoted

The simplest way to specify a string is to enclose it in single quotes (the character ').

To specify a literal single quote, escape it with a backslash (\).

http://www.php.net/manual/en/language.types.string.php

89

Answer

Solution:

Use the escape sequence\' to add a single quote to the string.

For better understanding, consider reading the manual: http://www.php.net/manual/en/language.types.string.php

627

Answer

Solution:

You need to escape those single quotes

  $row[7] = '<img title="vlc" id="vlc-playlist" src="./img/vlc.png" onclick="window.location=vlc.php?user=\'.$row[1].'&pass='.$row[2].'&type=vlc\'">';
40

Answer

Solution:

try this :

<?php
    echo "<img title=\"vlc\" id=\"vlc-playlist\" src=\"./img/vlc.png\" onclick=\"window.location='vlc.php?user=test&pass=testpass&type=vlc'\">\n";
?>

People are also looking for solutions to the problem: jquery - Search for a table within a database in Laravel 4 PHP Framework

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.