FCKEditor help

galaxyAbstractor

Community Advocate
Community Support
Messages
5,508
Reaction score
35
Points
48
I want to add like when they write [ PHP]text[ /PHP], it should become <source lang="php">text</source>

How would I do that?
 
Last edited:

Scoochi2

New Member
Messages
185
Reaction score
0
Points
0
I personally have never used and don't know FCKeditor, but if you have the string as a variable in PHP (for example, by submitting a form with the POST method), then the following will do just that:
PHP:
<?php
$string = 'my new array: [php]<?php $my_array = array(); ?>[/ php]';

$string = preg_replace("/\[php\](.+?)\[\/php\]/","<source lang=\"php\">$1</source>",$string);

echo $string;
?>
will output:
Code:
my new array: <source lang="php"><?php $my_array = array(); ?></source>
(space in example [/php] to prevent ending my own
PHP:
block)
 
Last edited:

galaxyAbstractor

Community Advocate
Community Support
Messages
5,508
Reaction score
35
Points
48
I personally have never used and don't know FCKeditor, but if you have the string as a variable in PHP (for example, by submitting a form with the POST method), then the following will do just that:
PHP:
<?php
$string = 'my new array: [php]<?php $my_array = array(); ?>[/ php]';

$string = preg_replace("/\[php\](.+?)\[\/php\]/","<source lang=\"php\">$1</source>",$string);

echo $string;
?>
will output:
Code:
my new array: <source lang="php"><?php $my_array = array(); ?></source>
(space in example [/php] to prevent ending my own
PHP:
block)[/quote]


nope does not work
 

dickey

New Member
Messages
128
Reaction score
0
Points
0
What scoochi2 posted should've worked, basically what you want is to use a string parser and string replace functions. so it should have worked.
 

Scoochi2

New Member
Messages
185
Reaction score
0
Points
0
What scoochi2 posted should've worked, basically what you want is to use a string parser and string replace functions. so it should have worked.
Indeed it does. The first thing I did was copy my entire code as is into a blank page.php
Next, I got rid of that space in the closing tag that I mentioned. Then I turned on PHP and ran it in my browser.
The following is what I saw:
my new array:
That's exactly what I expected to see. Doesn't mean it's right though ;)
Next, I viewed the source of the page (because I know that the HTML <source> shouldn't give me any visible results, but as it is HTML, it will appear in the page source. The following is the source of my page:
my new array: <source lang="php"><?php $my_array = array(); ?></source>

So yes, it does work :)


Vigge, can you confirm the results? IE, did you view the page in your browser and think it's not showing the string? Can you check the source and see if it's in there at all?
 
Last edited:
Top