Jump to content

highlight code help cheers.


redarrow

Recommended Posts

 

I am trying to count highlited code but witin a string please help thank you.

 

I am trying to get the number in rows to the code within the $message verable.

 

I got so far this. (it works but not properly)

 

<?php

$s="<?php echo john; ?>";

$hide=<<<hide_css
<style type="text/css"> 
.num { 
float: left; 
color: gray; 
text-align: right; 
margin-right: 6pt; 
padding-right: 6pt; 
border-right: 1px solid gray;} 
</style> 
hide_css;

function bbcode($s)
{
    $s = str_replace("]\n", "]", $s);
    $match = array('#\[php\](.*?)\[\/php\]#se');
    $replace = array("'<div>'.highlight_string(stripslashes('$1'), true).'</div>'");
    return preg_replace($match, $replace, $s);
}

if($s){

echo '<code class='.$hide_css.'>', implode(range(1, count(bbcode($s))), '<br />'), bbcode($s); '</code>'; 
exit;
}else{
echo " error redarrow no highligt code.....";
}
?>

Link to comment
https://forums.phpfreaks.com/topic/58003-highlight-code-help-cheers/
Share on other sites

Here the full version but as you can see the highlighted code needs to count the line number

so in essence i need a way to get in the varable and page count line number.

 

wont echo out with color code due to bad coding sorry.

 

 

//$var="<?php echo hello i love php; ?>"; // // // // // place this in the varable var to test ok.

<?php

$var="

[green]smile 1 [/green]
[smile1]http://www.google.co.uk/intl/en_uk/images/logo.gif[/smile1]

[i] [blue]smile 2 [/blue][/i]
[smile2]http://www.google.co.uk/intl/en_uk/images/logo.gif[/smile2]

[u][red]smile 3[/red][/u]
[smile3]http://www.google.co.uk/intl/en_uk/images/logo.gif[/smile3]

[b] smile 4[/b]
[smile4]http://www.google.co.uk/intl/en_uk/images/logo.gif[/smile4]

[i]smile 5 [/i]
[smile5]http://www.google.co.uk/intl/en_uk/images/logo.gif[/smile5]

[u] smile 6[/u]
[smile6]http://www.google.co.uk/intl/en_uk/images/logo.gif[/smile6]

[b] smile 7[/b]
[smile7]http://www.google.co.uk/intl/en_uk/images/logo.gif[/smile7]

[u][smile 8[/u]
[smile8]http://www.google.co.uk/intl/en_uk/images/logo.gif[/smile8]

[i]smile 9[/i]
[smile9]http://www.google.co.uk/intl/en_uk/images/logo.gif[/smile9]

[b]smile  10[/b]
[smile10]http://www.google.co.uk/intl/en_uk/images/logo.gif[/smile10]

";

function bbcode_format($var) {


$search = array(
'/\[b\](.*?)\[\/b\]/is',                                
'/\[i\](.*?)\[\/i\]/is',                                
'/\[u\](.*?)\[\/u\]/is',
'/\[img\](.*?)\[\/img\]/is',
'/\[url\](.*?)\[\/url\]/is',
'/\[url\=(.*?)\](.*?)\[\/url\]/is',
'/\[smile1\](.*?)\[\/smile1\]/is',
'/\[url\](.*?)\[\/url\]/is',
'/\[smile2\](.*?)\[\/smile2\]/is',
'/\[url\](.*?)\[\/url\]/is',
'/\[smile3\](.*?)\[\/smile3\]/is',
'/\[url\](.*?)\[\/url\]/is',
'/\[smile4\](.*?)\[\/smile4\]/is',
'/\[url\](.*?)\[\/url\]/is',
'/\[smile5\](.*?)\[\/smile5\]/is',
'/\[url\](.*?)\[\/url\]/is',
'/\[smile6\](.*?)\[\/smile6\]/is',
'/\[url\](.*?)\[\/url\]/is',
'/\[smile7\](.*?)\[\/smile7\]/is',
'/\[url\](.*?)\[\/url\]/is',
'/\[smile8\](.*?)\[\/smile8\]/is',
'/\[url\](.*?)\[\/url\]/is',
'/\[smile9\](.*?)\[\/smile9\]/is',
'/\[url\](.*?)\[\/url\]/is',
'/\[smile10\](.*?)\[\/smile10\]/is',
'/\[url\](.*?)\[\/url\]/is',
'/\[red\](.*?)\[\/red\]/is', 
'/\[blue\](.*?)\[\/blue\]/is',  
'/\[green\](.*?)\[\/green\]/is',
'#\[php\](.*?)\[\/php\]#se',
);

$replace = array(
'<strong>$1</strong>',
'<em>$1</em>',
'<u>$1</u>',
'<img src="$1" />',
'<a href="$1">$1</a>',
'<a href="$1">$2</a>',
'<img src="$1" />',
'<a href="$1">$3</a>',
'<img src="$1" />',
'<a href="$1">$4</a>',
'<img src="$1" />',
'<a href="$1">$5</a>',
'<img src="$1" />',
'<a href="$1">$6</a>',
'<img src="$1" />',
'<a href="$1">$7</a>',
'<img src="$1" />',
'<a href="$1">$8</a>',
'<img src="$1" />',
'<a href="$1">$9</a>',
'<img src="$1" />',
'<a href="$1">$10</a>',
'<img src="$1" />',
'<a href="$1">$11</a>',
'<img src="$1" />',
'<a href="$1">$12</a>',
'<font color="red">$1</font>',
'<font color="blue">$1</font>',
'<font color="green">$1</font>',
"'<div>'.highlight_string(('$1'), true).'</div>'",
);
$var = preg_replace ($search, $replace, $var);
return $var;
}
echo bbcode_format($var)

?>

Thorpe i read all your web site from top to bottom all off it on all subjects took 6 hours was fun theo.

 

I found all the information grate cheers.

 

The only thing i found deverstating was the web site it self wasent

for visually diabled people like my self but apart from that, It all got read to me nicly ok and thank you.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.