1 Replies - 396 Views - Last Post: 11 September 2013 - 01:09 AM Rate Topic: -----

#1 insik  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 68
  • Joined: 31-January 12

Putting Function Inside Quotes

Posted 11 September 2013 - 12:42 AM

Hi everyone. just wanna ask if it is possible to put a js function inside quotes.
example:
$result_final .= "
<table width='50%' border=1 cellpadding='9' cellspacing='5' style='position:absolute;top:5%;right:8%;'>
<tr><td>PRG-00$row[5]</td></tr>
<tr><td>$row[2]</td></tr>
<tr><td>$ ".number_format($row[3])."</td></tr>
<tr><td><input type='image' src='images/cartbutton.png' value='Add to Cart'onclick='".addtocart($row[0])."' /></td></tr>
</table>";       




if not. what are other ways?
thanks in advance.

Is This A Good Question/Topic? 0
  • +

Replies To: Putting Function Inside Quotes

#2 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3577
  • View blog
  • Posts: 10,442
  • Joined: 08-June 10

Re: Putting Function Inside Quotes

Posted 11 September 2013 - 01:09 AM

regarding the example, the functions are not inside the quotes/strings.

if you put functions inside a string, they won’t be parsed automatically (how should PHP know the difference of a Java­Script function call and a PHP function call?). you can however parse the string yourself for a function call (with said drawbacks) and execute the function (though that is—again—outside the string).

an, IMHO better, option is to use a template. in the simplest case: printf() (and related, cf. examples).
ex.
printf($template, $myVariable, myFunction($data));

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1