Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I display the contents of a webpage in an editor?

Status
Not open for further replies.

Chelsea7

Programmer
Aug 25, 2008
69
US
Hello everyone,

I'm trying to import a html file into an editor. I'm using CKEDITOR at CKEDITOR.COM. Think that I almost have it. Below will display the html file with no problem.


<?
$file = $_SERVER['DOCUMENT_ROOT'] . "/indexnew.html"; //Path to your *.txt file
$contents = file($file);
$string = implode($contents);

echo $string;
?>

EDITOR1 is the name I use for the editor.

However, how do I get it in the <text> </text> block so that it can be displayed. Something like;

<Form>
<textarea name="editor1">$string</text> what is the correct syntax for this?


 
Not really familiar with CKEditor but after looking at the documentation it looks like you just stick the contents of the file between the <textarea> tags.
CKEditor Documentation said:
But, as a matter of fact, CKEditor uses a textarea to transfer its data to the server. The textarea is invisible to the end user. So, to create and editor instance you must, ironically, create a textarea first:

<textarea name="editor1"><p>Initial value.</p></textarea>

[blue]Note that, if you want to load data into the editor, from a database for example, just put that data inside the textarea, just like the above example. [/blue]

So I would simply echo the file contents there:

Code:
<textarea name="editor1">[red]<?PHP echo $string; ?>[/red]</textarea>


----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Hello again,

Okay, here's the code by itself;


<?

$conn=mysql_connect("mysql", "user", "password") or die(mysql_error());
mysql_select_db("indexmain",$conn) or die(mysql_error());


$query="SELECT * FROM index1";
$result=mysql_query($query);
$num=mysql_numrows($result);
mysql_close();

$i=0;
while ($i < $num) {


$indexpi=mysql_result($result,$i,"indexpg");
echo $indexpi;

$i++;
}

?>


This works fine as it reads from the database. However, I'm still having trouble getting this data into the editor form.

I tried

<textarea name="editor1"><?php echo $indexpi ?></textarea>

But it just displays the statement <?echo $indexpi ?>

Here's the code for the editor. Do I have it in the wrong position?

--------------------------------------------------------
<script type="text/javascript" src="/ckeditor_3.0.1/ckeditor/ckeditor.js"></script>

<title>Untitled</title>

</head>

<body>

</p>

<?

$conn=mysql_connect("mysql", "ghvpcc", "godebra7294") or die(mysql_error());
mysql_select_db("indexmain",$conn) or die(mysql_error());


$query="SELECT * FROM index1";
$result=mysql_query($query);
$num=mysql_numrows($result);
mysql_close();

$i=0;
while ($i < $num) {


$indexpi=mysql_result($result,$i,"indexpg");
echo $indexpi;

$i++;
}


?>

<form enctype="multipart/form-data" action="/userpages/indexpcc.php" method="post">


<textarea name="editor1"><? echo $indexpi ?></textarea>

<p>
My Editor:<br />


<script type="text/javascript">
window.onload = function()
{
CKEDITOR.replace( 'editor1' );
};


</script>

<p>
<input type="submit" />
</p>


</form>

------------------------------------------

This is the only thing that's holding me up. Any assistance will be appreciated.
 
Is your PHP code in the same file as the editor textarea?

If your PHP part runs, then the <?PHP echo $var ?> should too if they are in the same page/file.

Also make sure it is [red]<?PHP[/red] and not just [blue]<?[/blue] As that may cause some issues.





----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Hello again. I'm still having problems try to load the contents from the database to the <textarea> </textarea>

Here is a simple php code that simply loads a webpage;

<?Php
$file = $_SERVER['DOCUMENT_ROOT'] . "/indexnew.html"; //Path to your *.txt file
$contents = file($file);
$string = implode($contents);

echo $string;
?>


This works fine. But the problem is trying to get that

<textarea><?php echo $string;?</textarea> to work.

All it does is display the syntax <?php echo $string;?> on screen.

I know this has to be in a form which it is but it will not work. Can anyone show me a working sample of this code from passing the information from the the php code to the Form and <textarea>?

The php does run on the server. I don't know what I'm doing wrong.

Below is the code I was trying to use to make this work.

<?Php
$file = $_SERVER['DOCUMENT_ROOT'] . "/indexnew.html"; //Path to your *.txt file
$contents = file($file);
$string = implode($contents);

echo $string;
?>

<form enctype="multipart/form-data" action="/userpages/indexpcc.php" method="post">

<p>
My Editor:<br />

<textarea name="editor1"><?php echo $string; ?></textarea>

<p>
<input type="submit" />
</p>

</form>

--------------
Any assistance will be much appreciated.
 
Add this line to finalize the setup of $string.
[tt] $string=htmlspecialchars($string);[/tt]
 
Is the PHP code that opens the file and places its contents in the $string variable in the same page file as your <textarea>?

Can anyone show me a working sample of this code from passing the information from the the php code to the Form and <textarea>?

There really is no science involved. As long as the PHP code that reads the file is above the textarea it should totally work.

The error you describe of the editor just containing the PHP string: "<?PHP echo $string ?>" tells me the PHP there is not being run.

Put this in a single file that has a php extension and try to run it:

Code:
<html>
<head><title></title>
<?PHP
$file = $_SERVER['DOCUMENT_ROOT'] . "/indexnew.html"; //Path to your *.txt file
$contents = file($file);
$string = implode($contents);
$string=htmlspecialchars($string); [green]/*Just to be sure*/[/green]

?>

<script type="text/javascript" src="/ckeditor/ckeditor.js"></script>
</head>
<body onload=>
<form enctype="multipart/form-data" action="/userpages/indexpcc.php" method="post">

        <p>
            My Editor:<br />

<textarea name="editor1"><?php echo $string; ?></textarea>

        <p>
            <input type="submit" />
        </p>

</form>

<script type="text/javascript">
	window.onload = function()
	{
		CKEDITOR.replace( 'editor1' );
	};
</script>
</body>
</html>

That should be all it takes, nothing more.

I tested this, and it works. It loads the editor, and the page contents inside.

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
It works! Finally! Thanks a million! Now I can finish up this project.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top