Mike Ezzati
Mike Ezzati

Reputation: 3166

JavaScript quotation marks change after echo

$t="<table>
      <tr>
        <td >
           <a  href='#' onClick='alert('some text!');'  >
        </td>

      </tr>
      <table>";

echo $t;

any inline javascript didn't work so I inspect the a element in browser and turns out its like:

<a  href="#" onClick="alert("some text');'>

What am I doing wrong with quotation marks?

Upvotes: 0

Views: 181

Answers (4)

Raheel Hasan
Raheel Hasan

Reputation: 6023

You got wrong quotes. Try this:

<a href='#' onclick=\"alert('some text!');\">

Upvotes: 0

Praveen kalal
Praveen kalal

Reputation: 2129

<?php 
$t="<table>
      <tr>
        <td >
           <a  href='#' onClick=\"alert('some text!');\"  >test</a>
        </td>

      </tr>
      <table>";

echo $t;
?>

Upvotes: 1

Code Lღver
Code Lღver

Reputation: 15603

<a  href='#' onClick=\"alert('some text!');\">

Use this code this will work fine.

Upvotes: 0

user1646111
user1646111

Reputation:

use:

$t=<<<EOT
<table>
      <tr>
        <td >
           <a  href='#' onClick='alert("some text!");'  >
        </td>

      </tr>
<table>
EOT;

or

$t="
<table>
      <tr>
        <td >
           <a  href='#' onClick='alert(\"some text!\");'  >
        </td>

      </tr>
<table>
";

echo $t;

Upvotes: 3

Related Questions