Acubi
Acubi

Reputation: 2783

single quote inside double quote in php

<input id="myID" onClick="CheckAll('A','B');" />

In the project,the above code need to be put into String(see 2nd snippet). However, the CheckAll() is already inside the single quote. If two parameters are inside Single quote in checkAll() like 2nd code snippet, the checkAll() won't work.

How to fix the 2nd code snippet?

Thanks in advance and any help will be really appreciated!

$string ="<input id='myID' onClick='CheckAll('A','B');' />"

Upvotes: 3

Views: 11294

Answers (3)

Mr Griever
Mr Griever

Reputation: 4023

Alternatively

$string = '<input id="myID" onClick="CheckAll(\'A\',\'B\');" />';

Upvotes: 0

genesis
genesis

Reputation: 50982

$string ="<input id='myID' onClick=\"CheckAll('A','B');\" />"

add escaping slashes

Upvotes: 1

Zebra
Zebra

Reputation: 4006

You can use backslash:

$string ="<input id=\"myID\" onClick=\"CheckAll('A','B');\" />"

Upvotes: 11

Related Questions