Hi.
I'm trying to insert PHP Code within the source-code but it get's deleted right after switching back to normal mode. Is there any chance to insert such code?
Thanks and Regards.
I'm trying to insert PHP Code within the source-code but it get's deleted right after switching back to normal mode. Is there any chance to insert such code?
Thanks and Regards.
Re: Insert PHP code?
FCKConfig.ProtectedSource.Add( /<\?[\s\S]*?\?>/g ) ;
in fckconfig.js
Re: Insert PHP code?
Viewing the source-code, the PHP-Code is visible. Apparently, it just gets "printed" into the source but is not beeing executed.
Example: I'm writing a normal text within FCKEditor and want to grab the current date.
How to do this?
(I attatched the source-code viewed in Firefox so you can see what i mean...)
Attachments:
Re: Insert PHP code?
Re: Insert PHP code?
Re: Insert PHP code?
Re: Insert PHP code?
Re: Insert PHP code?
yeah, maybe you must choose the extension .php in place of .html or .htm or .asp
That shall work. your server must have php installed otherwise it wont work
Re: Insert PHP code?
I had the same problem.
Do you use the "echo" command to print the website code?
If yes, you should use "eval", but you should close the php tag first when you eval you website, otherwise you get an error because eval try to open a php tag but it isn't closed at that point.
Error999
Re: Insert PHP code?
Change the html extention to php, then enter your php code in view source eg.
Re: Insert PHP code?
any ideas?
Re: Insert PHP code?
I mean...
Re: Insert PHP code?
Ex: When you include in database, the code go like <?php echo "Hello"; ?> - and that's fine, that's ok.
then, when you get the code from database you show like <?php echo $content; ?> $content is your code from database
the problem is you try to show the PHP code like <?php echo " <?php echo "Hello"; ?> "; ?> and this is the big problem, at the code source you will see the <?php echo "Hello"; ?> (in pink color),
all what you need to do is to create an .php page from your database content and then to include in your page , ex:
$content - is your code from database.
$link = "test.php";
$fp = fopen($link, 'w');
fwrite($fp, $content);
fclose($fp);
include ("test.php");
Then the php code will be processed well by your server.
Enjoy.
Re: Insert PHP code?
Hi All,
I have same problem. I can put php-code into DB succesfully, and inside narmal-text and only php-code. php-code is executed on the site is well. But when I want to edit it and load in editor, php-code invisible.
So, that even if the page was php-code, then it must be re-inserted each time when editing. How to solve this problem?
sorry for my english
Re: Insert PHP code?
Re: Insert PHP code?
fwrite($fp, $content);
statement, this is for files (myfile.txt, myfile.php, myfile.html).
to ouput from a database see sample below:
$user_name = "root";
$password = "";
$database = "addressbook";
$server = "127.0.0.1";
$db_handle = mysql_connect($server, $user_name, $password);
$db_found = mysql_select_db($database, $db_handle);
if ($db_found) {
$SQL = "SELECT * FROM tb_address_book";
$result = mysql_query($SQL);
while ($db_field = mysql_fetch_assoc($result)) {
print $db_field['ID'] . "<BR>";
print $db_field['First_Name'] . "<BR>";
print $db_field['Surname'] . "<BR>";
print $db_field['Address'] . "<BR>";
}
mysql_close($db_handle);
}
else {
print "Database NOT Found ";
mysql_close($db_handle);
}
Re: Insert PHP code?
use tag <phpcode></phpcode> and insert php codes between these tags in your admin panel where u r using fckeditor
e.g.
and use below function to print your output
in above example, only one instance of php can be executed, i have used the above code on my "contact us" page where i have created the form in fckeditor and used php mail function on that page through fckeditor so i have not give so much time to write code for multiple instances
thanks
Re: Insert PHP code?
Re: Insert PHP code?
-------
Alright, I think I figured out how to scale shahidmau's function. Using this modification, you can now enter as many different PHP code snippets as you want into the source view of CKeditor. Each snippet is interpreted (evaluated) by PHP and rendered as such.
The main difference is that preg_match_all is used instead of preg_match and most of the variables are now arrays. The preg_replace function is also limited to one (1) replacement per iteration.
I'm not a PHP-guru by any means (!), so please offer modifications to make this more efficient etc.
Call the function and output your content with something like the following:
Re: Insert PHP code?
<?php include"save.php"; ?>
into the source of the page FCKeditor is managing and it completely removes the tag once I leave source mode and return to wysiwyg view... or if I publish the page from source mode and then go back to open it again, it will then remove the php includes link.
Its also doing the same thing on a simple css rollover link:
<a id="oa" href="products-oa.php" title="OA"></a>
Very frustrating!
*** I tried the above recommendation about coding it like this:
<phpcode><?php include"save.php"; ?></phpcode>
but it did not work, everything between the <phpcode> tag is removed upon returning to preview mode.