1

I have bunch of HTML pages, each contains a line at the top of the page, the line is

<?xml version="1.0" encoding="UTF-8" ?>

pages were opening perfectly when I was running on localhost, now I have uploaded the files to server, and its giving me an error. the error is,

Parse error: syntax error, unexpected T_STRING in /home/a7597163/public_html/secretary.html on line 1

when I remove this line the page is displayed without any error, but the problem is I cant manually remove each line out of it, can anybody tell me how can I remove that line from each page... I tried using this

document.body.innerHTML = document.body.innerHTML.replace( /<?xml version="1.0" encoding="UTF-8" ?>/g, "");

but didnt work.

Thanks

vikas devde
  • 11,691
  • 10
  • 35
  • 42

4 Answers4

3

If it is a PHP error. It is being thrown at the server-end, well before the client sees it and the JavaScript has time to act on it. So no JavaScript can solve this.

So here, the solution would be to modify or rather remove the line at the source as it is syntactically incorrect in the PHP-file itself when short-tags are turned on.

If your hosting provider does allow you to edit php.ini, you could do short_open_tag=Off. But that will also cause any other <? ... ?> PHP-blocks to stop working.

Anirudh Ramanathan
  • 46,179
  • 22
  • 132
  • 191
2

The problem you are having is that the PHP interpreter on your live system has "short_tags" turned on, so it interprets <? as the start of a PHP tag.

You won't be able to do anything with the pages as they are because they will never get loaded. Your best bet is to write a script on your development machine to make the change and they re-upload the changed pages.

What the script looks like depends very much on what OS you are using locally.

Haqa
  • 476
  • 3
  • 14
1

If you have access to your php.ini you have to do the following :

Open it and set :

short_open_tag=On

to

short_open_tag=Off

Otherwise, change that line to

<?php echo 'xml version="1.0" encoding="UTF-8"'; ?>

Edit : And if you don't have that access, you can try this dirty way :

<<??>?xml version="1.0" encoding="utf-8"?>
Daneo
  • 508
  • 3
  • 17
1

First of all, the reason you get the error is that your server, for some reason, allows short tags. I.e. <? for your server means the same as <?php. Which is a questionable thing at best, but probably, it is best to disable it.

Now, there are zillions of programs that can do find and replace in files. One such popular program is sed So, you could do this:

$ find your/project/directory -type f -name "*.html" | sed -i 's/<[?]xml[^>]\+>//'

-i option of sed makes it replace the file in place, so you may want to create a backup first.

on Linux or Macintosh.

I've found this thread on SO How can you find and replace text in a file using the Windows command-line environment? about doing the same on Windows, but probably your code editor can do that too.

Community
  • 1
  • 1