Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

107
Views
How to get html data-attribute string from a php variable

I am constructing an html form in php with javascript and css, the following line of code works fine and displays a textarea with the required prefix:

$form .= '<textarea class="text" data-prefix="Message from: " ></textarea>';

However I want to include a php variable i.e

$form .= '<textarea class="text" data-prefix="Message from: $foo" ></textarea>';

This show the textarea with the prefix 'Message from $foo'. How do I show it with the value of $foo combined into the data-prefix i.e 'Message from Foo'?

Any advice would be appreciated, thanks.

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Either

$form .= "<textarea class='text' data-prefix='Message from: " . $foo. "' ></textarea>";

or

$form .= "<textarea class='text' data-prefix='Message from: {$foo}' ></textarea>";
about 4 years ago · Juan Pablo Isaza Report

0

Try to concat PHP variable with your string

$form .= '<textarea class="text" data-prefix="Message from: '.$foo.'" ></textarea>';
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!