Question

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.

Was it helpful?

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

OTHER TIPS

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

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\'">';

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";
?>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top