Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
PHP highlight code
10-15-2013, 07:30 AM
Post: #1
PHP highlight code
Hello , please anyone share php code highlight function of master land old script. .aspecialy request to admin. Thanks in advance. .
Find all posts by this user
Like Post Quote this message in a reply
10-15-2013, 11:19 AM
Post: #2
RE: PHP highlight code
why would you want the php highlight function from old masterland. it was shit and badly coded. and continuously broke when using smilies etc.
Find all posts by this user
Like Post Quote this message in a reply
10-15-2013, 12:08 PM
Post: #3
RE: PHP highlight code
so have u batter than this ?
Find all posts by this user
Like Post Quote this message in a reply
10-16-2013, 12:38 AM
Post: #4
RE: PHP highlight code
(10-15-2013 12:08 PM)mrbeen Wrote:  so have u batter than this ?

of course i do.

i made this myself. works for php 4 and php 5.
PHP Code:
function Php_Highlighter($data) {
$data preg_replace_callback('/\[PHP\](.*?)\[\/PHP\]/msi'create_function('$matches''{
$matches[1] = html_entity_decode($matches[1], ENT_QUOTES, \'UTF-8\');
$keyword_color = ini_get(\'highlight.keyword\');
$manual = \'http://php.net/\';
if(preg_match(\'/^(<\?|<\?php)\s*?.*?\s*?^\?>\s*?$/msi\', $matches[1], $new_matches)) {
$matches[1] = highlight_string($new_matches[0], 1);
} else {
$matches[1] = highlight_string(\'<?php\'.$matches[1].\'?>\', 1);
}
if(phpversion() < 5) {
$matches[1] = preg_replace(\'/([\w_]+)(\s*<\/font>)(\s*<font\s+color="\'.$keyword_color.\'">\s*\()/msi\', \'<a href="\'.$manual.\'$1" style="color: \'.$keyword_color.\'; font-weight: bold; text-decoration: none;" target="_blank">$1</a>$2$3\', $matches[1]);
$matches[1] = preg_replace(\'/(<font color="#000000">\t*?\r*?\n*?\s*?<font color="#0000BB">)<\?php\t*?\r*?\n*?\s*?<br \/>(.*?\t*?\r*?\n*?\s*?<\/font>\t*?\r*?\n*?\s*?)/msi\', \'$1$2\', $matches[1]);
$matches[1] = preg_replace(\'/(<font color="#000000">\t*?\r*?\n*?\s*?)<\?\t*?\r*?\n*?\s*?<br \/>(.*?\t*?\r*?\n*?\s*?<\/font>\t*?\r*?\n*?\s*?)/msi\', \'$1$2\', $matches[1]);
$matches[1] = preg_replace(\'/<br \/>\t*?\r*?\n*?\s*?<\/font><font color="#0000BB">\?>\t*?\r*?\n*?\s*?<\/font>\t*?\r*?\n*?\s*?<\/font>\t*?\r*?\n*?\s*?<\/code>/msi\', \'</font></code>\', $matches[1]);
$matches[1] = preg_replace(\'/<br \/>\?>\t*?\r*?\n*?\s*?<\/font>\t*?\r*?\n*?\s*?<\/code>/msi\', \'</font></code>\', $matches[1]);
$matches[1] = preg_replace(\'/(<font color="#0000BB">\?>\t*?\r*?\n*?\s*?<br \/>\t*?\r*?\n*?\s*?<\/font>)\?>(\t*?\r*?\n*?\s*?<\/font>\t*?\r*?\n*?\s*?<\/code>)/msi\', \'$1$2\', $matches[1]);
} else {
$matches[1] = preg_replace(\'/([\w_]+)(\s*<\/span>)(\s*<span\s+style="color: \'.$keyword_color.\'">\s*\()/msi\', \'<a href="\'.$manual.\'$1" style="color: \'.$keyword_color.\'; font-weight: bold; text-decoration: none;" target="_blank">$1</a>$2$3\', $matches[1]);
$matches[1] = preg_replace(\'/(<span style="color: #000000">\t*?\r*?\n*?\s*?<span style="color: #0000BB">)<\?php\t*?\r*?\n*?\s*?<br \/>(.*?\t*?\r*?\n*?\s*?<\/span>\t*?\r*?\n*?\s*?)/msi\', \'$1$2\', $matches[1]);
$matches[1] = preg_replace(\'/(<span style="color: #000000">\t*?\r*?\n*?\s*?)<\?\t*?\r*?\n*?\s*?<br \/>(.*?\t*?\r*?\n*?\s*?<\/span>\t*?\r*?\n*?\s*?)/msi\', \'$1$2\', $matches[1]);
$matches[1] = preg_replace(\'/<br \/>\t*?\r*?\n*?\s*?<\/span><span style="color: #0000BB">\?>\t*?\r*?\n*?\s*?<\/span>\t*?\r*?\n*?\s*?<\/span>\t*?\r*?\n*?\s*?<\/code>/msi\', \'</span></code>\', $matches[1]);
$matches[1] = preg_replace(\'/<br \/>\?>\t*?\r*?\n*?\s*?<\/span>\t*?\r*?\n*?\s*?<\/code>/msi\', \'</span></code>\', $matches[1]);
$matches[1] = preg_replace(\'/(<span style="color: #0000BB">\?>\t*?\r*?\n*?\s*?<br \/>\t*?\r*?\n*?\s*?<\/span>)\?>(\t*?\r*?\n*?\s*?<\/span>\t*?\r*?\n*?\s*?<\/code>)/msi\', \'$1$2\', $matches[1]);
}
$matches[1] = str_replace(\'&nbsp;\', \' \', $matches[1]);
return \'<div class="codebox">\'.$matches[1].\'</div>\';
}'
) , $data);
return 
$data;


use it like:
PHP Code:
echo str_replace("\r\n""<br/>\r\n"Php_Highlighter($Row2['post_content'])).'<br/><br/>'."\r\n"

this will take the code/data from database that the members have posted. and display it on the page in a nice user friendly way.

demo of working code:
http://codemafia.uk.to/c2/Working-On-A-I...ndex1.html
Find all posts by this user
Like Post Quote this message in a reply
[-] The following 1 user Likes Ghost's post:
mrbeen (10-16-2013)
10-16-2013, 05:47 AM
Post: #5
RE: PHP highlight code
Thank you very much . . U r real helper always.
Find all posts by this user
Like Post Quote this message in a reply
10-16-2013, 07:20 AM
Post: #6
RE: PHP highlight code
(10-16-2013 12:38 AM)Ghost Wrote:  
(10-15-2013 12:08 PM)mrbeen Wrote:  so have u batter than this ?

of course i do.

i made this myself. works for php 4 and php 5.
PHP Code:
function Php_Highlighter($data) {
$data preg_replace_callback('/\[PHP\](.*?)\[\/PHP\]/msi'create_function('$matches''{
$matches[1] = html_entity_decode($matches[1], ENT_QUOTES, \'UTF-8\');
$keyword_color = ini_get(\'highlight.keyword\');
$manual = \'http://php.net/\';
if(preg_match(\'/^(<\?|<\?php)\s*?.*?\s*?^\?>\s*?$/msi\', $matches[1], $new_matches)) {
$matches[1] = highlight_string($new_matches[0], 1);
} else {
$matches[1] = highlight_string(\'<?php\'.$matches[1].\'?>\', 1);
}
if(phpversion() < 5) {
$matches[1] = preg_replace(\'/([\w_]+)(\s*<\/font>)(\s*<font\s+color="\'.$keyword_color.\'">\s*\()/msi\', \'<a href="\'.$manual.\'$1" style="color: \'.$keyword_color.\'; font-weight: bold; text-decoration: none;" target="_blank">$1</a>$2$3\', $matches[1]);
$matches[1] = preg_replace(\'/(<font color="#000000">\t*?\r*?\n*?\s*?<font color="#0000BB">)<\?php\t*?\r*?\n*?\s*?<br \/>(.*?\t*?\r*?\n*?\s*?<\/font>\t*?\r*?\n*?\s*?)/msi\', \'$1$2\', $matches[1]);
$matches[1] = preg_replace(\'/(<font color="#000000">\t*?\r*?\n*?\s*?)<\?\t*?\r*?\n*?\s*?<br \/>(.*?\t*?\r*?\n*?\s*?<\/font>\t*?\r*?\n*?\s*?)/msi\', \'$1$2\', $matches[1]);
$matches[1] = preg_replace(\'/<br \/>\t*?\r*?\n*?\s*?<\/font><font color="#0000BB">\?>\t*?\r*?\n*?\s*?<\/font>\t*?\r*?\n*?\s*?<\/font>\t*?\r*?\n*?\s*?<\/code>/msi\', \'</font></code>\', $matches[1]);
$matches[1] = preg_replace(\'/<br \/>\?>\t*?\r*?\n*?\s*?<\/font>\t*?\r*?\n*?\s*?<\/code>/msi\', \'</font></code>\', $matches[1]);
$matches[1] = preg_replace(\'/(<font color="#0000BB">\?>\t*?\r*?\n*?\s*?<br \/>\t*?\r*?\n*?\s*?<\/font>)\?>(\t*?\r*?\n*?\s*?<\/font>\t*?\r*?\n*?\s*?<\/code>)/msi\', \'$1$2\', $matches[1]);
} else {
$matches[1] = preg_replace(\'/([\w_]+)(\s*<\/span>)(\s*<span\s+style="color: \'.$keyword_color.\'">\s*\()/msi\', \'<a href="\'.$manual.\'$1" style="color: \'.$keyword_color.\'; font-weight: bold; text-decoration: none;" target="_blank">$1</a>$2$3\', $matches[1]);
$matches[1] = preg_replace(\'/(<span style="color: #000000">\t*?\r*?\n*?\s*?<span style="color: #0000BB">)<\?php\t*?\r*?\n*?\s*?<br \/>(.*?\t*?\r*?\n*?\s*?<\/span>\t*?\r*?\n*?\s*?)/msi\', \'$1$2\', $matches[1]);
$matches[1] = preg_replace(\'/(<span style="color: #000000">\t*?\r*?\n*?\s*?)<\?\t*?\r*?\n*?\s*?<br \/>(.*?\t*?\r*?\n*?\s*?<\/span>\t*?\r*?\n*?\s*?)/msi\', \'$1$2\', $matches[1]);
$matches[1] = preg_replace(\'/<br \/>\t*?\r*?\n*?\s*?<\/span><span style="color: #0000BB">\?>\t*?\r*?\n*?\s*?<\/span>\t*?\r*?\n*?\s*?<\/span>\t*?\r*?\n*?\s*?<\/code>/msi\', \'</span></code>\', $matches[1]);
$matches[1] = preg_replace(\'/<br \/>\?>\t*?\r*?\n*?\s*?<\/span>\t*?\r*?\n*?\s*?<\/code>/msi\', \'</span></code>\', $matches[1]);
$matches[1] = preg_replace(\'/(<span style="color: #0000BB">\?>\t*?\r*?\n*?\s*?<br \/>\t*?\r*?\n*?\s*?<\/span>)\?>(\t*?\r*?\n*?\s*?<\/span>\t*?\r*?\n*?\s*?<\/code>)/msi\', \'$1$2\', $matches[1]);
}
$matches[1] = str_replace(\'&nbsp;\', \' \', $matches[1]);
return \'<div class="codebox">\'.$matches[1].\'</div>\';
}'
) , $data);
return 
$data;


use it like:
PHP Code:
echo str_replace("\r\n""<br/>\r\n"Php_Highlighter($Row2['post_content'])).'<br/><br/>'."\r\n"

this will take the code/data from database that the members have posted. and display it on the page in a nice user friendly way.

demo of working code:
http://codemafia.uk.to/c2/Working-On-A-I...ndex1.html

IT gives <br /> at end of each line help me
Find all posts by this user
Like Post Quote this message in a reply
10-16-2013, 08:08 AM
Post: #7
RE: PHP highlight code
(10-16-2013 07:20 AM)mrbeen Wrote:  IT gives <br /> at end of each line help me

try to use function without the str_replace
like so:
PHP Code:
echo Php_Highlighter($Row2['post_content']).'<br/><br/>'."\r\n"

it might be the way you first add the data to database that its responding the way it does.

i have no clue why the poster above me would recommend changing <br/> to <br> since <br> isnt technically correct html in most doctypes.
Find all posts by this user
Like Post Quote this message in a reply
[-] The following 1 user Likes Ghost's post:
syaefulloh (01-26-2014)
10-16-2013, 08:22 AM
Post: #8
RE: PHP highlight code
(10-16-2013 08:08 AM)Ghost Wrote:  
(10-16-2013 07:20 AM)mrbeen Wrote:  IT gives <br /> at end of each line help me

try to use function without the str_replace
like so:
PHP Code:
echo Php_Highlighter($Row2['post_content']).'<br/><br/>'."\r\n"

it might be the way you first add the data to database that its responding the way it does.

i have no clue why the poster above me would recommend changing <br/> to <br> since <br> isnt technically correct html in most doctypes.

Still it gives <br/>

Like

$image_name = str_replace(' ','_',$_FILES["file"]["name"]); <br />
$image_details = getimagesize($_FILES["file"]["tmp_name"]); <br />
$current_width = $image_details[0]; <br />
$current_height = $image_details[1]; <br />
<br />
if($current_height > $max_height_size_allowed || $current_width > $max_width_size_allowed) { <br />
$new_width = $max_width_size_allowed; <br />
$new_height = $max_height_size_allowed; <br />
$tmp = imagecreatetruecolor($new_width, $new_height); <br />
Find all posts by this user
Like Post Quote this message in a reply
[-] The following 1 user Likes mrbeen's post:
syaefulloh (01-26-2014)
10-16-2013, 08:36 AM (This post was last modified: 10-16-2013 08:36 AM by Ghost.)
Post: #9
RE: PHP highlight code
(10-16-2013 08:22 AM)mrbeen Wrote:  
(10-16-2013 08:08 AM)Ghost Wrote:  
(10-16-2013 07:20 AM)mrbeen Wrote:  IT gives <br /> at end of each line help me

try to use function without the str_replace
like so:
PHP Code:
echo Php_Highlighter($Row2['post_content']).'<br/><br/>'."\r\n"

it might be the way you first add the data to database that its responding the way it does.

i have no clue why the poster above me would recommend changing <br/> to <br> since <br> isnt technically correct html in most doctypes.

Still it gives <br/>

Like

$image_name = str_replace(' ','_',$_FILES["file"]["name"]); <br />
$image_details = getimagesize($_FILES["file"]["tmp_name"]); <br />
$current_width = $image_details[0]; <br />
$current_height = $image_details[1]; <br />
<br />
if($current_height > $max_height_size_allowed || $current_width > $max_width_size_allowed) { <br />
$new_width = $max_width_size_allowed; <br />
$new_height = $max_height_size_allowed; <br />
$tmp = imagecreatetruecolor($new_width, $new_height); <br />

i think i see the issue. its not getting the <br/> tag correctly cos of a space in the tag.

try one of these solutions:
PHP Code:
echo str_replace(array("<br />\r\n""<br />\n""<br />\r"), '<br/>'Php_Highlighter($Row2['post_content'])).'<br/><br/>'."\r\n"

or

PHP Code:
echo str_replace(array("<br />\r\n""<br />\n""<br />\r""<br />"), '<br/>'Php_Highlighter($Row2['post_content'])).'<br/><br/>'."\r\n"

or

PHP Code:
echo str_replace(array("<br />\r\n""<br />\n""<br />\r""<br />"), ''Php_Highlighter($Row2['post_content'])).'<br/><br/>'."\r\n"

see if either of them help the situation.
they might look the same. but they are all slightly different.
Find all posts by this user
Like Post Quote this message in a reply
[-] The following 2 users Like Ghost's post:
mrbeen (10-16-2013), syaefulloh (01-26-2014)
10-16-2013, 08:38 AM
Post: #10
RE: PHP highlight code
Solved thank you
Find all posts by this user
Like Post Quote this message in a reply
[-] The following 1 user Likes mrbeen's post:
syaefulloh (01-26-2014)
Post Reply 


Forum Jump:


User(s) browsing this thread: 1 Guest(s)