Welcome Guest ( Log In | Register)



 
Reply to this topicStart new topic
> Making This Compatable With Trap17's Php
AlternativeNick
post Nov 20 2006, 07:23 AM
Post #1


Super Member
*********

Group: Members
Posts: 210
Joined: 7-June 06
Member No.: 24,817



ok, i have a php script that is not compatable with trap17's php (4.4.4) i believe it was made to run on php 5, if anyone could help, id really appreciate it, thanks smile.gif

CODE

<?php
function something($info) {
$script = new mirc_script($info);
$script->highlight();
return $script->get_script();
}
class mirc_script {
private $data = array();
public $chars = array();

// By specifying TRUE for $beautify here you can save a bit a processing time rather than call the beautify method later
public function __construct($script = NULL,$beautify = FALSE) {
if ($beautify && $script !== NULL) {
$this->beautify($script);
} else {
$this->script = $script;
}
}

// Attempt to beautify the script a bit
public function beautify($input = NULL) {
// Beautify the script
$script = ($input === NULL ? $this->script : $input);

// Break apart commands separated by |
$script = preg_replace('/\s+\|\s+/',"\n",$script);

// Put newlines before } and after {
$script = preg_replace('/\s+\}\s*(?:\s|$)/',"\n}\n",$script);
$script = preg_replace('/(?<=\s|^)\{\s+/',"{\n",$script);

// Put () around some if conditions
$script = preg_replace('/(if|elseif|while)\s+([^\(].*?)\s+\{/','\1 (\2) {',$script);
$this->script = $script;
}

public function __set($var,$value) {
$this->data[$var] = $value;

if ($var == 'script') {
if ($value !== NULL) {
$this->split_script();
}
}
}

public function __get($var) {
return $this->data[$var];
}

// Split the script into an array of characters
private function split_script() {
$this->script = str_replace("\r",'',$this->script);

$this->chars = array_slice(preg_split('//',$this->script),1,strlen($this->script));
array_map(array(&$this,'escape_chars'),&$this->chars);
}

// Escape HTML characters
private function escape_chars(&$char) {
$char = str_replace(array('&','<','>'),array('&amp;','&lt;','&gt;'),$char);
}

// Apply highlighting to the script
public function highlight() {
$open = '\s,!@^&*\050='; // Characters that start a token
$close = '\s,!@^&*\051'; // Characters that end a token

$script = $this->script;

// Conditional Operators
$operators = '!?(?:=|==|===|>|<|>=|<=|\/\/|\\\\|&|isin|isincs|iswm|isnum|isletter'.
'|isalnum|isalpha|islower|isupper|ison|isop|ishop|isvoice|isvo|isreg|ischan|' .
'isban|isaop|isavoice|isignore|isprotect|isnotify|iswmcs|\|\||&&|\+|\-|\*|%|\^)';

// Patterns to match for different parts of mIRC scripts
$patterns = array(
// Comments
//Block Style
// Here I've put a d in front of the pattern. This is a lazy thing I did to tell the script to delete the matched portion of text. It's not part of the regular expression.
'd/\\013?\s*(\/\*.*?\*\/)\s*\\013?/s'
// The first element of the replacement will go before each callback, and the second element after each callback
=> array('<span class="mirc_comment">','</span>'),
// Single Line
'd/^\s*(;.*)$/m'
=> array('<span class="mirc_comment">','</span>'),

// Number
'/(?<=^|['.$open.'])([+-]?[\d]+?(?:\.[\d]+?)?)(?=$|['.$close.'%])/m'
=> array('<span class="mirc_number">','</span>'),

// Identifier
'/(?<=^|['.$open.'])(\$[^\s\050\051\[,]+)/m'
=> array('<span class="mirc_identifier">','</span>'),
// Identifier Property
'/(?<=\051)(\.[^\s$\051]+)/m'
=> array('<span class="mirc_identifier">','</span>'),

// Variable
'/(?<=^|['.$open.'])(\%[^'.$close.']+)(?=$|['.$close.'])/m'
=> array('<span class="mirc_variable">','</span>'),

// Operators
'/(?<=[\s])('.$operators.')(?=[\s])/m'
=> array('<span class="mirc_operator">','</span>'),

// Special Characters
'/([\[\]\{\}\050\051\|]+)/m'
=> array('<span class="mirc_character">','</span>'),

// Events
'/(?<=^)\s*(on|ctcp|raw)\s+([^\:]+?)sad.gif[^\:]+?):/m'
=> array('<span class="mirc_event">','</span>'),

// Commands
'/(?<=^|[\{\|]\s)\s*([^\$\%\s]+?)(?=\s|$)/m'
=> array('<span class="mirc_command">','</span>'),
// Command Switches
'/(?<=^|[\{\|]\s)\s*(?:[^\$\%\s]+?)\s+(-[^\s]+)(?=\s|$)/m'
=> array('<span class="mirc_command_switch">','</span>'),
);

$patterns_keys = array_keys($patterns);
foreach ($patterns_keys as $rpattern) {
// Iterate through each pattern
if ($rpattern{0} == 'd') {
// The 'd' switch means delete the text after matching
$delete = TRUE;
$pattern = substr($rpattern,1);
} else {
$delete = FALSE;
$pattern = $rpattern;
}
if (preg_match_all($pattern,$script,$matches,PREG_OFFSET_CAPTURE)) {
// Get all matches for this pattern
array_shift($matches); // Shift off the part we don't want
foreach ($matches as $matches2) {
// Iterate through each callback
foreach ($matches2 as $match) {
// Iterate through each match of each callback
list($text,$offset) = $match;
// Put the first element before the first character of the callback
$this->chars[$offset] = $patterns[$rpattern][0] . $this->chars[$offset] ;
// Put the second element after the last character of the callback
$this->chars[$offset -1 + strlen($text)] = $this->chars[$offset-1 + strlen($text)] .
$patterns[$rpattern][1];
if ($delete) {
// Delete the entire matched text so we don't match it again
$script = substr($script,0,$offset) . str_repeat(' ',strlen($text)) .
substr($script,$offset + strlen($text));
}
} // End iterate through each match of callback
} // End iterate through each callback
} // End if
} // End iterate through each pattern
return $line;
}

// Returns the script after processing
// Specify TRUE for $indent to have the script indented
public function get_script($indent = FALSE) {
// Implode the array of characters into the finished script
$output = implode('',$this->chars);
if ($indent) {
$lines = explode("\n",$this->script);
$output = explode("\n",$output);
$level = 0;
foreach ($lines as $key => &$line) {
if ($in_comment) {
// Don't indent parts of the script that are commented out
if (preg_match('/^\s*\*\//',$line)) { $in_comment = FALSE; }
continue;
}
// Check for beginning of a comment
if (preg_match('/^\s*\/\*/',$line)) { $in_comment = TRUE; continue; }
if (preg_match('/^\s*;/',$line)) { continue; }

// Remove spaces at the beginning of the line
$output[$key] = preg_replace('/^\s*/','',$output[$key]);

// Decrease indentation if there's a }
$decrease = preg_match_all('/(?<=\s|^)}(?=\s|$)/',$line);
// Increase indentation if there's a {
$increase = preg_match_all('/(?<=\s|^|smile.gif{(?=\s|$)/',$line);
// Increase indentation if there's a $&
$increase = preg_match_all('/\$\&\s*$/',$line);

$difference = $increase - $decrease;

if ($difference < 0) { $level += $difference; $difference = 0; }
if ($level < 0) $level = 0;

$output[$key] = str_repeat(' ',$level * 2) . $output[$key];

$level += $difference;
$difference = 0;
}
$output = implode("\n",$output);
}
return $output;
}
}

?>
Go to the top of the page
 
+Quote Post
fffanatics
post Nov 20 2006, 07:44 PM
Post #2


Privileged Member
*********

Group: [HOSTED]
Posts: 936
Joined: 14-April 05
From: West Chester, PA
Member No.: 5,636



Post the errors it shows when you run it so we know where exactly to look in order to fix it. Im not an expert on what is in what version of php even though i do a ton of programming in it. Let us know where the errors are and we will help you.
Go to the top of the page
 
+Quote Post
AlternativeNick
post Nov 22 2006, 05:39 AM
Post #3


Super Member
*********

Group: Members
Posts: 210
Joined: 7-June 06
Member No.: 24,817



this is the error that im getting right now

QUOTE

Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /home/altscr/public_html/forum/Sources/highlight.php on line 8
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Making Mycent Transferable(18)
  2. Ftp In Visual Basic 6.0(3)
  3. Softwares For Banner Making!(13)
  4. A Cat Making Noise As It Drinks Milk With It's Paw(1)
  5. Inbox Dollars(35)
  6. Making Money Creating Logo's(20)
  7. Making A New Website Need Idea's(19)
  8. The Sims 2 Bodyshop(38)
  9. Making My Own Browser(11)
  10. Trap17's Ssh(8)
  11. Making A Scroll Bar In Flash(5)
  12. Making Banners And Skins For Invision Power Board V1.3 Final(0)
  13. Tips For Making New Friends(18)
  14. Give Me Website Ideas..(31)
  15. My Modern History Speech- Is It Good? Am I Making Any Historical Inaccuracies?(2)
  1. Best Online Money Making Programmes(9)
  2. .::gunz Online Clan::.(17)
  3. Im Making A Mmorpg >>(14)
  4. Making Winrar Archives(13)
  5. Where Am I Making Mistake(10)
  6. Browser Compatibility Problem With Firefox - Javascript + Css(3)
  7. Open Program Copyrights For Third World Nations(7)
  8. Making A Screenshot(3)
  9. Making Realistic Clouds(0)
  10. Help Needed: Rewritting Uris From .htaccess(0)
  11. What Are The Steps To Making A Website?(19)
  12. [ask] Making Video When We Use An Application In Our Computer?(5)
  13. Making Games(18)
  14. Making A Picture Viewer Website(3)
  15. Making A Simple Signature With Adobe Photoshop(3)


 



- Lo-Fi Version Time is now: 22nd November 2008 - 10:16 PM