Preserving format of xml file in textarea

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jateeq
Forum Newbie
Posts: 14
Joined: Mon Mar 01, 2010 12:16 pm

Preserving format of xml file in textarea

Post by jateeq »

Hello,

I would like to open an xml file in php, and display the contents, without parsing the xml, in a textarea for editing. Currenlty, I am simply storing all lines in an array and listing the lines, but this messes up the formatting which is especially important with regards to xml files to promote user comprehension.

My code:

Code: Select all

 
$lines = file_get_contents($filelocation, 'r');
$content = file($filelocation, FILE_IGNORE_NEW_LINES);
$smarty-> assign('content', $content);
 
And then I go on to display each line in a smarty template. If you are not familiar with smarty, it doesn't matter, the result should be the same as echoing out the lines in php.

I have attached a screenshot of what the file currently looks like. On the left is output using GeSHi, on the right is the output in the textarea using the aforementioned code. If I can make the latter look even remotely like the former, it'll help a lot.

I am open to suggestions involving javascript, but I don't think that has anything to do with how I display these lines.

Thanks,
Jawad.
Attachments
Screenshot for output of supplied code
Screenshot for output of supplied code
Editing_session.png (124.14 KiB) Viewed 377 times
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Preserving format of xml file in textarea

Post by requinix »

file() gives you an array. You don't want an array - especially with the newlines ignored.
file_get_contents() gives you a string. You want a string.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Preserving format of xml file in textarea

Post by Christopher »

Search for "javascript XML editor". Maybe something like this:

http://marijn.haverbeke.nl/codemirror/
(#10850)
Post Reply