I am using Jquery text editor. I copy and paste the XML as given below in texteditor
<shoes>
<shoe>
<shouename>Shoue</shouename>
</shoe>
</shoes>
Then I click on save and the XML saved in Mysql DB. Then when I edit the same I see "Shoue" in texteditor field. But i want to show it as it is as below in texteditor
<shoes>
<shoe>
<shouename>Shoue</shouename>
</shoe>
</shoes>
I think texteditor endering the XML with HTML.
How can I show XML as it is in texteditor using PHP. So that I could edit the XML and save.
try htmlspecialchars() and read about XSS - you should use this function always when you want output user's data on HTML page.
As variant, try Twig templates engine - very simple and have built-in escaping.
Related
I'm trying to use CKEditor to input rich text into my database, which works except the formatting is not the same when I try to output the rich text the user entered. The position of elements such as pictures is incorrect.
I currently have the following code:
Input:
$pitch = htmlspecialchars($_POST['editor1']);
$sql = mysql_query("UPDATE projects SET pitch='$pitch' WHERE id='$proj_id'");
Output:
$pitch = htmlspecialchars_decode(stripslashes($pitch));
The result is then echoed back which creates the incorrect formatting.
Does anyone know what I'm doing wrong?
This has nothing to do with PHP.
Contents of the framed editor (which you use) is styled by the contents.css file which you can find in the main CKEditor directory. However, this stylesheet is not used on your page, so content created in editor is not styled by the same rules.
The correct approach is - style content on your site and then copy (or somehow reuse, e.g. by setting config.bodyClass and config.contentsCss) these styles in editor contents.
Remember, that you also need to set styles available in styles drop down. They are by default configured as for the sample, but when you'll change available styles, you need to update styles.js file too.
I am building a rich text editor using JavaScript and an editable iFrame, and I am wondering how I can use php to save the contents of the iframe to an html file.
WARNING The link http://simple.procoding.net/2008..... provided by iWantSimpleLife generates a Javascript Obfuscation alert. That site may be infected.
Correct me if I'm wrong, but isn't an iframe basically a page you're retrieving ?
If so, then file_get_contents ( http://php.net/manual/fr/function.file-get-contents.php ) should do the trick.
First, With Javascript copy the contents of the Html text of the iframe and then paste them to text in a textarea.
Then submit the text area contents to PHP script that safe it in a text file with html extension on your webserver.
Recall file system manual of PHP
http://www.php.net/manual/en/ref.filesystem.php
Use javascript to get the content. http://simple.procoding.net/2008/03/21/how-to-access-iframe-in-jquery/
This took me about 5 minutes to Google.
I was converting a HTML file to PDF using dompdf. I managed to get the desired result but a problem arose, the HTML file needs to be converted to PHP because it will receive data from a form (from another file)!
The dompdf in this case doesn't work and it not shows the result of what was written in the form.
I think what you search is a template Engine to replace values in a HTML file.
There are some Engines like Smarty, TWIG.
You can parse your HTML file and with the HTML return you can create your PDF file.
Perhaps its a bit oversized for your case but you could build your own short engine and parse your HTML file and replace your specified Tags with the form values.
You can create your html file automaticaly in temp. After request to your php file, your file generates automaticaly a .html file (in temp), then create your pdf from this file.
I am new to php and I want to create an php engine which changes the web content of a webpage with PHP with the use of data in mysql. For example (changing the order of navigation links on a webpage with the order of highest click count) I am not sure how PHP will read the HTML file and change the elements in the HTML file and also output the HTML file with the changes. Is this possible?
I am not quite sure why you would want to generate the html, read it, change it and then output it. It seems to be a lot easier to just generate it the way you want to in the first place.
I am not sure how PHP will read the HTML file and change the elements in the HTML file and also output the HTML file with the changes. Is this possible?
You could use file_get_contents:
$html = file_get_contents($url);
Then use a html-parser like Simple HTML DOM Parser, change what you want to do and output it.
If you want to modify HTML structure, use ganon - HTML DOM parser for PHP
include('path/ganon.php');
// Parse the google code website into a DOM
$html = file_get_dom('http://code.google.com/');
foreach($html('p[class]') as $element) {
echo $element->class, "<br>\n";
}
Let's say we have a .doc & .docx files. I want to use LiveDocx in PHP to load the files, read it's content and strip the text from inside it. Then save it to an HTML string.
Can this be done?
I've searched the documentation, and it seams that LiveDocx only loads .doc & .docx template files only!
You can save using external libraries and simply grab the text from the XML within the files:
http://www.webcheatsheet.com/PHP/reading_the_clean_text_from_docx_odt.php
I think you can find what you need in this example.
I might be wrong, but I think they call them "template" files because they act like a template but are still normal .doc/.docx documents. I suggest you simply try to run that example.
I think you can use TextControl that improves phpLiveDocx TextControl link
Using this you can also import pdf doc and docx
When you do document conversion on LiveDocX, you need to do a mailmerge and then retrieve the document. Even though you aren't inserting any new content, you need to do a mailmerge that replaces a dummy placeholder with dummy content.
So, the process I'd suggest is:
1) Set your source document as local template
2) Merge a dummy field with dummy content
3) Retrieve your document as HTML
4) Use a script server side to remove the html and leave only the content (Something like, remove everything between the HEAD tags, then strip_tags on the rest)
5) You should be left with your content as a simple string - I'm not sure it'll be too meaningful, but might be useful for building something like search indices.