Member Avatar for LastMitch

Hi

I have a few questions.

1) I want to put the a text editor in the admin section so I can edit the 'home page' context from the admin section which is in php language (I have no context in the admin created yet, this will be my first page).

2) Can anyone recommend me a free text editor?

It's pretty embrassing, I'll pretty out of date with a lot things now.

The one I have used for a long time is called "FCKeditor" and the company doesn't update it anymore (FCKeditor 2.6.6).

3) I don't know how to write this php code another words I don't know where to start.

Any demo or sample that I can see or get a big picture, I want to learn how to write it but I don't know where to start.

i really appreciate it if someone can explain to me what to do.

Thanks,

Recommended Answers

All 30 Replies

you can use notepad++, just google it, it's free and very easy to use
and you might want to check out http://www.w3schools.com/ for the tutorial

Member Avatar for LastMitch

@ azareth

Thanks for reply! I need text editor that I can used online on my website not notepad. But thanks for the suggestions!

I also use notepad++, and I like Programmers Notepad as well. There is also PSPad.

For online editing, some editors have ftp capability or addons (I know notepad++ does) that let you edit files locally that reside on a remote server.

Also check out these links
http://sourceforge.net/projects/ontext/ (now defunct, but you can still download it)
http://www.tinymce.com/
http://ckeditor.com/

http://www.catswhocode.com/blog/10-useful-online-code-editors

of course there are more if you are willing to pay for them.

Hi,

Let me write a demo first then, I will post it here after I tested it a couple of times.. This is the same method I was using, because I was pretty lazy using the ftp. So, all my php files are generated from my website. At least, I can edit my php files without FTP applications..just Internet connection and I am good to go.

Hold on, please... thanks for the PM... :).

Member Avatar for LastMitch

@ Hearth

Thanks for the reply of online editors. I know you and azareth mention notepad++, it's in C++ and it's bit complicate for me to used in the website. I forgoting about C, C++, VB for a few years now. But thanks for the lists.

Member Avatar for LastMitch

@ veedeoo

Thanks for the reply! Any suggestions for "Text Editors" ?

So, all my php files are generated from my website.

I'm trying to do that too. It's a bit complicate if the Text Editor doesn't have any php files attached to it meaning part of the script.

FCKeditor

Has a file a php that let you put the editor on the admin section and edit my php files.

But it's pretty out dated and I'm pretty out dated too regarding about Text Editors.

Recent years Text Editors are in JQuery which needs this:

http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"

to function.

LastMitch - yes when FCKeditor stopped they went to CKeditor. Hearth gave you the link above. They give all the directions in their wiki as to how to implement it.
Here is what I do. Include this in the head tags:

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

Then on a page where I'm making a new page:

<span style="color:red">* Page Content</span> (this is the actual text on the page):<br />
<textarea cols="80" id="pagecontent" name="pagecontent" rows="10">Main text here</textarea>
<script type="text/javascript">
                //<![CDATA[

                    CKEDITOR.replace( 'pagecontent' );

                //]]>
                </script>

Then on the next page after submission it is added to the database.
On another admin page to edit what is already a page in the database, I use this:

<span style="color:red">* Page Content:</span><br />
<textarea cols="80" id="pagecontent" name="pagecontent" rows="10"><?php echo $row->pagecontent; ?></textarea>
<script type="text/javascript">
                //<![CDATA[

                    CKEDITOR.replace( 'pagecontent' );

                //]]>
                </script>

This brings up what was in the database.

commented: Thanks for the example! +2

I also really enjoy notepadd++

I use Notepad++ for coding, but inline editing TinyMCE (easy to setup, open source, large support community if needed)

@lastMitch,

I did not know, that it was almost midnight when I responded on this thread. Anyways, I managed to write some simple script to make you edit php, html, css, js files right in your admin area..

I wrote a single class for this, but it needs an upgrade at the moment, so before heading out for school today, I managed to write a simple script that will do as what you need.

Please Protect this script from public access at all cost. I strongly suggest using .htaccess protection on top of the login credentials as admin. NEVER and DO NOT allow any members of your site (if any) to access this script.

I did a test run twice.. and I can confirmed that it is working on my side. The only thing that this file don't have is the fancy highlight capabilities, and systax validation.

Here we go...

sTep ONe.. save this file as stepone.php.. or any name you want will do just as fine..

<?php
####  WARNING! THIS SCRIPT MUST BE PROTECTED FROM PUBLIC ACCESS ###########
## written by veedeoo or PoorBoy 2012
## feel free to use at your application.
## filename : stepone.php


## first we define our file extension allowed. 
$ext = array('.php','.html','.js','.css','.tpl');
## we define our current working directory where the dumper should be looking for files.
$work_directory = getcwd();

## we create a file dumper function
function dump($dir,$ext) {

$d = dir($dir);
while (false!== ($file = $d->read()))
{
$extension = substr($file, strrpos($file, '.'));

## we search the extesion match, otherwise we don't do anything 
if ((array_search($extension, $ext) !== FALSE)){
$d_files[$file] = $file;

}
}
$d->close();
asort($d_files);

return $d_files;
}
?>


<form method = "post" action ="writter.php">

<p>
<label>Select Action</label>
<select name ="action">
<option selected="selected"></option>
<option value = "1">Create New file</option>
<option value ="2">Edit File</option>
</select>
</p>

<!-- we will add existing file edit capabilities here later -->
<!-- we call our file dumper function -->
<!-- sometimes I do a reverse array just like below, pleas look at my function dump above. Pretty cool huh? -->

<?php $array = dump($work_directory,$ext);?>


<p>
<label>Select file to Edit </label>
<select name="editFile">

<?php foreach ($array as $key => $file) {
 $td_item= $file;

 ?>
<option >
<?php echo $td_item;?>
</option>

<?php
}
?>

</select>

</p>
<p>

If new file Selected above, Type file name ONLY!
<br/>
<label>File Name   </label>  <input type = "text" name = "fname"/>

</p>
<p>

Select file extension for the above filename.
<br/>
<label>Select File Type</label>
<select name = "ftype" >
<option>php</option>
<option>html</option>
<option>js</option>
<option>css</option>
<option>tpl</option>
</select>
<br/>
</p>
<p>
<input type="submit" name="process" value="submit">
</p>
</form>

Script above is just a simple php and html combined in one page.., the usage is pretty much self-explanatory. The only thing that you need to be very careful is selecting edit file, and the file option below. Make sure you are not editing these files (stepone.php and writter.php). If you select new file, please type in the filename ONLY without the file extension. bElow it is a file type select option, where you can select what type of file extension you want to use on your new file.

Step TWO. copy and save this as writter.php . This file will responsible in writting your php, html, js, css, tpl file as needed.

<?php
####  WARNING! THIS SCRIPT MUST BE PROTECTED FROM PUBLIC ACCESS ###########
## written by veedeoo or PoorBoy 2012
## feel free to use at your application.
## filename: writter.php

## You can Change the work directory if you want.. otherwise files will be created in the same directory as writter.php
$work_directory = getcwd();
echo $work_directory."<br/>";

if(isset($_POST['process'])&& (!empty($_POST['action']))){
    //if(!empty($_POST['action'])){
        $action = $_POST['action'];
    //}
    if($action == 1){
        ## we need to create a new file
        $newFileName = $_POST['fname'];
        $newFileType = $_POST['ftype'];
        $thisNewFile = $work_directory."/".$newFileName.".".$newFileType;
        ## first we need to check if file don't exist
        if (!file_exists($thisNewFile)) {
           ## stop the undefined index error
           $filler = "";
          switch ($newFileType){

            case "php":
            ## must use single quotes when it is necessary
            $filler .='<?php ';
            $filler .="\n\n";
            $filler .='##fileName: '.$newFileName.'.'.$newFileType.'##';
            $filler .="\n\n";
            $filler .='echo "hello World";';
            $filler .="\n\n";
            $filler .='?>';
            break;

            ## our html file
            case "html":
            $filler .='<html>';
            $filler .="\n\n";
            $filler .='<!-- '.$newFileName.'.'.$newFileType.'-->';
            $filler .="\n\n";
            $filler .='<head>';
            $filler .="\n\n";
            $filler .='</head>';
            $filler .="\n\n";
            $filler .='<body>';
            $filler .="\n\n";
            $filler .='<!-- Type your html tags below -->';
            $filler .="\n\n";
            $filler .='</body>';
            $filler .="\n\n";
            $filler .='</html>';
            break;

            default:
            $filler .= "## type your codes here";
            break;

        }
         $writeThisFile = fopen($thisNewFile,"w");
         fwrite($writeThisFile,$filler);
         fclose($writeThisFile); 

      } 
      ## file already exist we don't do anything
      $fileToRead = $newFileName.".".$newFileType;
      $fileLink = $newFileName.".".$newFileType;

    }
    ## If we want to edit existing file
    ## make existing file be the $thisNewFile
    elseif($action == 2){

        $thisNewFile = $work_directory."/".$_POST['editFile'];
        $fileLink = $_POST['editFile'];
        $fileToRead = $fileLink;
    }

 ## even though it is redundant, we need to double check file exist once again before loading it to he editor
if (file_exists($thisNewFile)) {

//$thisFile = $thisNewFile; 
$readThisFile = $fileToRead;
$thisNewFileLink = $fileLink;
}
}
//$loadcontent = $readThisFile; 
    if(isset($_POST['submit'])) {
     $readThisFile = $_POST['nFile'];
     $thisNewFileLink = $_POST['nFile'];
     $codesUpdate = $_POST['string'];
         $codesUpdate = stripslashes($codesUpdate);
        $fp = @fopen($readThisFile, "w");
        if ($fp) {
            fwrite($fp, $codesUpdate);
            fclose($fp);
                               }
                }
    $fp = @fopen($readThisFile, "r");
        $readThisFile = fread($fp, filesize($readThisFile));
        $readThisFile = htmlspecialchars($readThisFile);
        fclose($fp);

?>

<!-- html section .. this can be in separate file -->
<html>
<head>
<style>
textarea{
    width: 700px;
    color: #ffffff;
    border: 3px solid grey;
    padding: 5px;
    font-family: Tahoma, sans-serif;
    background: #000000;

}

</style>
</head>
<body>
<div>
<a href="<?php echo $thisNewFileLink;?>" target="_Blank">Preview</a>
<br/>
<form method=post action="<?php echo $_SERVER['PHP_SELF']?>">
<input type="hidden" name="nFile" value="<?php echo $thisNewFileLink;?>">
<input type="hidden" name="thisFile" value="<?php echo $readThisFile?>">
<pre class="brush: php; highlight: [5, 15]; html-script: true">
<textarea name="string" cols="70" rows="25"><?php echo $readThisFile?></textarea>
</pre>
<br>
<input type="submit" name="submit" value="Save Changes">  
</form>
</div>
</body>
</help>

Once again, the script above is a simple demonstration of how we can use the php to write another files.. Please test the script and let me know..

It is pretty basic at this time, but it will give you the option to edit your script using just the browser, without the FTP program envolved.

Later on, I will add another function where it can write a history records of the last edited files.. that should be a cool features..

I might have to rewrite this a little later... maybe after the summer semester...

commented: Thanks for hard work! You made my day! =) +0
Member Avatar for diafol

I'm a little unclear as to how you want this to work. If you need html snippets, then a wysiwyg editor like CKeditor / TinyMCE / jWYSIWYG etc etc should be fine.

If you need a php editor, I would suggest that you do this locally with a mature IDE-like text editor. Aptana, Netbeans, Notepad++, Bluefish are all viable suggestions. You then upload the file / snippet via FTP. Why? Synching is one reason. You don't want a different state or unsynched situation to exists between your remote and local testing servers. Although online editing of php may sound like a great idea, in practice I would warn against it. As most remote sites are 'live' any error-producing code will be evident and visible - although if you are just using theis for the admin area, you may be lucky. Even so, modifying php in one file often means modifications upstream and downstram, e.g. with regard to include files, classes etc. These may inpinge on the 'public' site and produce unexpected results or even security issues.

Having a fully functioning, robust and secure local solution is always my first step to updating my live sites. Even then, following FTP, extensive testing must be considered as different environments can cause problems.

My 2p.

commented: The Kid forgot to read the whole thread +2
Member Avatar for LastMitch

@ dannette

Thanks for the reply and the example!

Member Avatar for LastMitch

@ Squidge

@ whit89

Thanks for the reply!

Member Avatar for LastMitch

@ veedeoo

I did not know, that it was almost midnight when I responded on this thread.

I'm not mad you but can't stop laughing! You made my day with this post! I had a long day at work!

I don't want you to get upset because you did a lot work, but did you actually read the whole thread? It seems that you only read #1 but forgot #2 & #3.

About the scripts you wrote ... Are you trying to fried my brain?

I just want to know a free text editor that I can used to put it in the admin section. I don't know how to put the text editor in the admin section meaning setup the text editor in php language (create php). I apologies for the miscommunication. I know are still in school and busy studies things happend.

Did you read "Ardav" first line?

I'm a little unclear as to how you want this to work. If you need html snippets, then a wysiwyg editor like CKeditor / TinyMCE / jWYSIWYG etc etc should be fine.

He is asking me not you how this is going to work? Well, I tell Ardav I'm not sure either!

If you need a php editor, I would suggest that you do this locally with a mature IDE-like text editor. Aptana, Netbeans, Notepad++, Bluefish are all viable suggestions. You then upload the file / snippet via FTP. Why? Synching is one reason. You don't want a different state or unsynched situation to exists between your remote and local testing servers. Although online editing of php may sound like a great idea, in practice I would warn against it. As most remote sites are 'live' any error-producing code will be evident and visible - although if you are just using theis for the admin area, you may be lucky. Even so, modifying php in one file often means modifications upstream and downstram, e.g. with regard to include files, classes etc. These may inpinge on the 'public' site and produce unexpected results or even security issues.
Having a fully functioning, robust and secure local solution is always my first step to updating my live sites. Even then, following FTP, extensive testing must be considered as different environments can cause problems.

The second paragraph is referred to your script!

If you are not tired if you have time can you actually write something simple. Thanks.

Member Avatar for LastMitch

@ Ardav

I'm a little unclear as to how you want this to work. If you need html snippets, then a wysiwyg editor like CKeditor / TinyMCE / jWYSIWYG etc etc should be fine.

The kid just forgot to read the whole thread. I can understand why you were confused when you saw what he wrote. Believe me I'm more lost. I didn't expect something like that. You and the kid made my day with this post! I had a long long day at work! I'm not as stress now since I read this thread. Thanks.

If you need a php editor, I would suggest that you do this locally with a mature IDE-like text editor. Aptana, Netbeans, Notepad++, Bluefish are all viable suggestions. You then upload the file / snippet via FTP. Why? Synching is one reason. You don't want a different state or unsynched situation to exists between your remote and local testing servers. Although online editing of php may sound like a great idea, in practice I would warn against it. As most remote sites are 'live' any error-producing code will be evident and visible - although if you are just using theis for the admin area, you may be lucky. Even so, modifying php in one file often means modifications upstream and downstram, e.g. with regard to include files, classes etc. These may inpinge on the 'public' site and produce unexpected results or even security issues.

Having a fully functioning, robust and secure local solution is always my first step to updating my live sites. Even then, following FTP, extensive testing must be considered as different environments can cause problems.

My intention was to know a free text editor that I can used to put it in the admin section. I don't know how to put the text editor in the admin section meaning setup the text editor in php language because most text editor doesn't have a php that connected the folder

dannette example is the closest one that I can understand but she has javascript.

I want something like this

include_once("../fckeditor/fckeditor.php");

fckeditor.php <--- This is the file I want to learn to create because most text editor don't have that and I don't know how to do that.

I don't know how to explained it more I hope anyone can understand.

I just want to know a free text editor that I can used to put it in the admin section

We have all pointed out several options available to you. Have you actually checked out any of the links or Googled for any of the suggestions?

I don't know how to put the text editor in the admin section meaning setup the text editor

I'm sure all of the suggested products have clear setup instructions on their websites.

He is asking me not you how this is going to work? Well, I tell Ardav I'm not sure either!

So, what exactly are you looking to get out of this thread? Since none of the suggestions so far seem to have satisfied your request, how can we help?

Member Avatar for LastMitch

@ Hearth

We have all pointed out several options available to you. Have you actually checked out any of the links or Googled for any of the suggestions?

I did

I'm sure all of the suggested products have clear setup instructions on their websites.

not all

So, what exactly are you looking to get out of this thread? Since none of the suggestions so far seem to have satisfied your request, how can we help?

To learn something and have fun!

I live in NYC and I have a mortage to pay, water bill, gas bill, electric bill, verizon bill. I'm pretty stress. Unless you want to pay my bills!

I been on Daniweb for close to 3 months now! I learn a lot already. I met some good mentors along the way

You know I feel you don't have enough patience.

I met someone name Biiim and he's a web developer and guess what he's from UK.

He help me learn a lot. You can check my thread that has 115 replys. Do you know how long is that? That thread last over a month. He explain and teach me how to read and understand the scripts and modify it.

I have to wake 5 am everyday USA to post a message on Daniweb so he can read from his time which UK. That's a 5 hours differences!

Guess what? The Thread is Solved!

Can you speak with me over a month on a thread. I doubt that.

This forum is the only place I can re-learn the languages I took in college a long time ago.

If you don't want to help me ... fine leave ... I don't like negative in my thread.

@Mitch

I apologise, I wasn't intending to be negative - just pointing out that as far as I can tell everyone is posting basicallythe same things, and it doesn't seem to be what you are looking for. So, you need to clarify precisely what you want.

Your last post to Al does this a bit better. So, you are wanting to write your own WYSIWYG editor for PHP? or you want to find an existing one that is purely PHP based?

AFAIK all online WYSIWYG editors require javascript, otherwise you would have to post every change to the server before you could see the update - which would be a very tedious process to edit anything.
I have even written one myself in the past, but it also involves javascript in order to update the visual display of what you are editing.

The easiest one I have used is probably TinyMCE, but it is javascript based. You simply include this code in your page to convert a textarea into wysiwyg editor:

<script type="text/javascript" src="../tiny_mce/tiny_mce.js"></script>
<script type="text/javascript">
tinyMCE.init({
        mode : "textareas"
});
</script>

(taken from http://www.tinymce.com/wiki.php/Installation)

Member Avatar for diafol

JS based editors are a must if you want WYSIWYG. php is not able to interactively alter input on the browser. Many of the newer generation of editors are pure js, some based on jQuery. I have used CKEditor and TinyMCE extensively and find them to be very good at what they do. Another one I found very useful was Spaw2 from Solmetra - although developement seems to have halted on this one. I've provided translations (localizations) for the majority of the main editors and find that they're much of a muchness with regard to simple editing. Advanced features such as file management (uploading images etc) is one of the things that sort the mature editors from the rest. Some editors only include this as a paid feature.

php is great for many things, but not IMO WYSIWYG text editors.

you can try fckeditor

If you download CKeditor from ckeditor.com, you will see there is a ckeditor.php included. CKeditor replaces FCKeditor that you were used to using. Here is a page that explains how to implement (along with CKfinder which is used for managing image files):
Click Here
If you read this, you can see why CKeditor replaced FCKeditor Click Here

commented: Thanks for the link! +2
Member Avatar for LastMitch

@ Ardav

Thanks for replying again~!!

Advanced features such as file management (uploading images etc) is one of the things that sort the mature editors from the rest

I agree.

Member Avatar for LastMitch

@ sftranna

Thanks for the reply! Did you read my first post?

Member Avatar for LastMitch

@ dannette

Thanks for the replying again. I will take a look at the link. Thanks

Member Avatar for LastMitch

@ dannette

I took a look at the link your provided and yes this is something what I was looking for. I will follow the directions and if I have anymore questions I will post it on here. Thanks.

I use PSPad for editing websites and being able to FTP ...as in, I open up PSPad, connect ftp to my site, browse to the file I want to edit, double click to open it up, make changes, file > save to save it back to FTP.

As per a stricktly PHP based editor it's pretty simple.

I've written a very basic editor, you will probably need to modify it to work with your site, your database is probably different than what I've got here for example.

Feel free to ask me questions, I hope that it's enough to get you started with PHP, if you do anything programming you will catch on pretty quickly.

This is just the edit page, you may want to take a stab at a 'new page' page yourself and see if you can do it from what you pick up here.

Goodluck!

<?php

// Make sure you are connected to database
//include("config.php");


// Save page content / overwrite existing page
if(isset($_POST['submit'])){
$name = mysql_real_escape_string(trim($_POST['name']));
$content = mysql_real_escape_string(trim($_POST['content']));
$ud = mysql_query("UPDATE pages SET page_content='$content' WHERE page_name='$page_name' LIMIT 1");
if($ud){
echo "Page has been saved!";
}else{
echo "There was an error: ".mysql_error();
}
}

if(!empty($_GET['edit'])){
// Get the existing page content so we can then edit it
$edit = mysql_real_scape_string(trim($_GET['edit']));
$get_content = mysql_query("SELECT * FROM pages WHERE page_name='$edit' LIMIT 1");
$count_get_content = mysql_num_rows($get_content);

if($count_get_content > 0){
// We got a page back from mysql, now edit it:
$array_get_content = mysql_fetch_array($get_content); // we limited to 1 result max on line 11, so we do not need a while loop!
$content = $array_get_content['page_content'];
?>
<a href="edit.php">Cancel Changes</a><br /><br />
<form action="edit.php?edit=<?php echo $_GET['edit']; ?>" method="post">
<textarea name="content"><?php echo $content; ?></textarea>
<input type="submit" name="name" value="<?php echo $_GET['edit']; ?>" />
<input type="submit" name="submit" value="Save Page" />

</form>
<?php
}else{
echo "Sorry, but the page {$_GET['edit']} does not exist in the database. <a href=\"new.php?new={$_GET['edit']}\">Create new page?</a>";
}
}else{
//List all pages

$gp = mysql_query("SELECT * FROM pages");
$cgp = mysql_num_rows($gp);
if($cgp > 0){
while($agp = mysql_fetch_array($gp)){
extract($agp);
/* page_id page_name page_content ...these are the mysql column names*/
echo "<a href=\"edit.php?edit=$page_name\">$page_name</a><br />";
}
}else{
echo "<i>No pages</i>";

}
?>
Member Avatar for LastMitch

@ cjohnweb

Thanks for the reply and the example!

PSPad

I never heard of it but I will look into it.

Member Avatar for LastMitch

@ cjohnweb

You have some interesting websites that you created in your portfolio! It's pretty!

Member Avatar for LastMitch

@ dannette

The link you provide was good, but not the one I need it's for "CKFinder" but I end up installing the "CKEditor " anyway. I didn't need the "CKFinder" I only want to understand how the "CKEditor " works. But thanks for the link!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.