This is crap!
Try a better example (this may in a class or function):
class.ubb.php
Code:
<?php
class Ubb {
public $text;
public $smilies = array(
':)' => "smile.gif",
':(' => "sad.gif",
':D' => "biggrin.gif",
':d' => "biggrin.gif",
':p' => "tongue.gif",
':P' => "tongue.gif",
':-)' => "unsure.gif",
'(A)' => "angel.gif",
'(a)' => "angel.gif",
':s' => "blink.gif",
':S' => "blink.gif",
':$' => "blush.gif",
'(h)' => "cool.gif",
'(H)' => "cool.gif",
':\'(' => "cry.gif",
'--' => "dry.gif",
'-_-' => "dry.gif",
'^^' => "happy.gif",
'^_^' => "happy.gif",
':|' => "huh.gif",
';d' => "laugh.gif",
';D' => "laugh.gif",
':@' => "mad.gif",
':o' => "ohmy.gif",
':O' => "ohmy.gif",
':0' => "ohmy.gif",
'8S' => "woot.gif",
'8s' => "woot.gif",
'8)' => "wacko.gif",
';)' => "wink.gif",
);
public function __construct($text) {
$this->text = $text;
}
public function addCodes() {
$text = $this->text;
# Change characters in html
$text = htmlspecialchars($text);
# Add enters
$text = nl2br($text);
# Run all possibilities
foreach($this->smilies AS $find => $replace)
{
# Creates an image for each smiley
$text = str_replace(htmlentities($find), '<img src="https://www.mpgh.net/forum/images/smileys/'.$replace.'" alt="smileys" />', $text);
}
# Add your own image
$text = preg_replace('#\[img\](http(s)?://)([a-zA-Z0-9\-\.,\?!%\*_\#:;~\\&$@\/=\+]+)\[/img\]#', '<img src="\\1\\3" alt="" />', $text);
# Makes colored characters
$text = preg_replace('#\[color=(\#[0-9A-F]{6}|[a-z\-]+)\](.*?)\[/color\]#si', '<font color="\\1">\\2</font>', $text);
return $text;
}
}
?>
How to use?
Set at the top of your document
Code:
<?php
require_once('class.ubb.php');
$file = file_get_contents("updates.txt");
$text = new Ubb($file);
?>
And this where you want the text:
Code:
<?php
$text-> addCodes();
?>