I am having a textbox, in that i have loaded a xml file.
After editing and saving the xml content into the xml file, the content is not in the right formate.
While loading again, its not in the xml format
How to save a the content into the file with neat alignment?
Please help me
For ExampleI need to save like the following
<section>
<value>a</value>
<value>b</value>
</section>
But after saving its looks like
<section><value>a</value><value>b</value></section>
Thanks,Praveen J
As Gordon says your question makes no sense - the XML fragment is still "well-formed" (but its far from complete) so it is in the right format.
Do you mean you want to preserve the format it was submitted in? In which case output it using <pre>...</pre> tags. OTOH there are standard tools out there which wil format XML according to specific standards - e.g. geshi
C.
I think is issue is that it doesn't preserve whitespace, so opening the xml file later shows it all in a single line as opposed to spaced/tabbed as originally created.
You can try white-space: physical as a CSS attribute on your textarea. Alternatively you can try adding the attribute/value pair "wrap=hard" to your textarea declaration. Both methods should preserve whtepace.
Related
I have this situation trying to disable a sequence into a .php file (the black commented lines, back-to-top text button);
I've read about block commenting in notepad ++ and setting the language of the file but the comment it looks like is not implemented properly.
What I've done :
-File / Open the .php file,
(already it looks like it is viewed in php language judging by the colors)
-Selection between 355-359 lines and Block Comment (ctrl+shift+Q).After that, I've added the text but it doesn't look like the other existing comments.
Any thoughts? Thanks,
PHP comments only work when you are inside PHP mode (between <?php and ?>).
When you are outputting HTML, you need HTML comments which take the form <!-- comment which does not include two adjacent hyphens -->.
The PHP within an HTML comment will still execute and the results will be output to the browser. It looks like your PHP only outputs data and doesn't do any significant processing, so that will probably be sufficient. You might, especially in other cases, be better off simply deleting the code and then restoring it from your version control system's history later.
For that part of code you should comment using:
<!-- your comment -->
As you are using html (you closed the part of your php code by ?> )
Should be a pretty obvious answer, but I have spent several hours looking at existing similar questions and none are working for me
My code generates logfiles for (manual) debugging etc
If I use print_r($array,TRUE) to capture the output from an array as a string and then echo with <pre> tags to display that on screen, it's really easy to view and understand what's going on.
However, when I write the same info to the logfile, fwrite doesn't preserve the line break and indentation formatting so there is a splurge of info that takes significant amounts of time to make sense of, esp larger arrays and objects.
I have tried using output buffer
$string=print_r($array,TRUE);
ob_start();
echo "<pre>$string</pre>";
$outputBuffer = ob_get_contents();
ob_end_clean();
fwrite($handle,$outputBuffer);
However, all that's now happening is that I see the <pre> tags added into the basic, non-layout output
e.g.
<pre>DOING QUERY: SELECT * FROM event_triggers WHERE DateTime<='2015-09-16 13:04:30'</pre><pre>Completed checking for event triggers</pre>
You can't just add HTML tags to a document, open it in an editor expect HTML tags to be rendered correctly.
You either have to setup your log file as a HTML file (doesn't neccessarily have to be valid, so just add .html to the file name and open it in the browser) or use var_dump to echo out the variables.
Rename file to .html extension and just open with a browser. Browser will detect it with line break html document. <pre></pre> will output like <p></p> in the browser.
I have generated an XML file that and one of the nodes contains data that I need to be rendered in a specific way with line breaks/new lines:
This should be the first line
this should be the second line
When I load the XML in browser and view source it looks spot on, I can copy and paste the data with the structure maintained. In the browser however it is rendered as:
This should be the first line this should be the second line
Any ideas?
There is nothing in XML that would assist you with formatting text in the browser. If you want to format XML data for viewing in the browser you should transform the XML into HTML and apply the approriate HTML tags that will format the text as you want it to appear.
I've got a php file that takes an xml file (generated by an outside source) and reformats it with CSS & HTML. A number of the XML tags are things I don't want to see in the final version, so I have them hidden. The end result is something like this:
<html>
<div style="display: none">
content i don't want to see
</div>
content I do want to see.
</html>
Is there a way I can take the resulting html file as it's displayed in the browser window,
content I do want to see.
…and save that as a text file? I want it to ignore all the hidden <div> tags and only save what can otherwise be selected and copied by the user.
I've looked around for an answer to this but I'm not even really sure what I'm looking for or how to search it.
I've also tried this:
ob_start();
file_put_contents('filename.htm', ob_get_contents());
ob_end_flush();
… but that's doesn't solve it. I have a number of tags in the outputted test (> etc) that need to be saves as they are displayed, and ob_get_contents() takes the page's source code, not the displayed version.
This matters because the outputted page is also PHP that has been generated based on other factors, so I need to use html unicode values to keep the $ signs and quotes from messing up the source PHP.
I hope that was clear. Thanks in advance for any help or suggestions.
I think you have to strip out the unneeded part manually, using a RegEx something, which maybe like:
$content_raw = ob_get_contents();
$content_stripped = preg_replace($content_raw, '<div style="display: none">[^<>]*</div>', '');
file_put_contents('filename.htm', $content_stripped);
I have some multi line text saved in MySql database (VARCHAR 255). When i load it, and process it using standard php function "nl2br", it echoes fine (multi line). But, when i load multi line text from database, make it "nl2br" and then send it to javascript (so it gets displayed in textarea), it won't be displayed! What's wrong?
echo "<SCRIPT>FillElements('".$subject."','".$text."');</SCRIPT>";
P.S.
FillElements function:
function FillElements(Sub,Txt)
{
document.getElementById('txtSubject').value=Sub;
document.getElementById('txtMessage').value=Txt;
}
textareas don't actually store the contents in an attribute like value in the same manner as input elements. They actually store the contents in in between the <textarea> and </textarea> tags. Meaning that the contents is actually treated as CDATA in the document.
<textarea>
This is my Content
</textarea>
Produces a text area with "This is my Content" as the contents.
The implication of this is that you cannot use the code you have to alter the contents of a textarea. You have to alter the innerHTML property of the textarea. I have set up a simple example here:
http://jsfiddle.net/wFZWQ/
As an aside, since you are populating the fields using PHP on the creation of the page, why not merely fill the data in the HTML markup, this seems like a long way round to do it.
Also, since you don't appear to be using it, have you seen [jQuery][1] it abstracts alot of things out, so instead of typing document.getElementById("the_id") to get an element you can use CSS selectors and merely write $("#the_id") to get the same element. You also get a load of useful functions that make writing javascript mucxh easier.
[1]: http://jquery.com jQuery
Newline tags (<br />) don't cause actual new lines in <textarea>.
You can pass the "real" newlines (\n) to your <textarea>, though.
I created a fiddle for that.
EDIT: For the updated FillElements code:
$subject = "String\nWith\nMultiple\nLines";
printf('<script type="text/javascript">FillElements(%s)</script>',
json_encode($subject)
);
My guess is that your HTML source code looks like this:
<script>FillElements("foo","foo
bar
baz");<script>
Correct?
In JavaScript, strings cannot span multiple lines...