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

188
Views
Illegal character in javascript with php header

I am using php to bundle javascript and CSS files.

...
$js_files = ['path/to/script.js', 'path/to/jquery.js'];

header( "Content-type: application/javascript" );

foreach($js_files as $path){
   echo file_get_contents($path);
}
...

But when I add them to my HTML page:

<script src="http://localhost:63342/project/assets/assets.php"></script>

it gives me syntax error Uncaught SyntaxError: illegal character U+0001

...function(){
   S.event.add(this�Yÿø��, t, i, r, n)
}...

�Yÿø�� is an illegal string, but my original code is correct:

...function(){
   S.event.add(this, t, i, r, n)
}...

also tried readfile() and mb_convert_encoding() for encoding but still not working!

Edit

Manually it's working correctly:

<script src="http://localhost:63342/project/assets/jQuery/jquery.3.6.js"></script>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can set the header like that: header('Content-Type: text/html; charset=utf-8');

to avoid the problem.

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!