Witam, podaje do ocenki

klase bbcode
metoda findImage jeszcze nie działa a reszta to:
Kod
[b]hadzia[/b]
[i]hadzia[/i]
[u]hadzia[/u]
[url:http://adres.pl?hadzia=cos:anchor]
proszę o wyrozumiałość dopiero wychodzę z programowania strukturalnego
<?php
/*
* @ Obsluga BBcode
* @ 09.05.06
* @ hadzia...
*/
class bbCode
{
/* tekst do przeszukania */
var $text;
/* podmiana bold
* @ hadzia
*/
var $regBold = '/\[()\](.*)\[\/([b])\]/';
/* podmiana italic
* @ hadzia
*/
var $regItalic = '/\[()\](.*)\[\/([i])\]/';
/* podmiana underline
* @ hadzia
*/
var $regUnderline = '/\[()\](.*)\[\/([u])\]/';
/* podmiana na linki
* @ http://www.hadzia.pl/adres.roz?=zm
* @ [url:http://adres.pl:anchor]
*/
var $regUrl = '/\[(url{1}):(http[s]?:\/\/{1}[\w\.-]+\.\w{2,6}.*?):([^:]+)\]/';
/* podmiana na img
* @ [img:X]
* @ X - int
*/
var $regImage = '/\[(img):(\\d+)\]/';
function setString( $text ){
return $this->text = $text;
}
function changeCode(){
return $this->findUrl( $this->findUnderline( $this->findItalic( $this->findBold( $this->text ) ) ) );
}
function findBold( $sBold ){
} else {
return $sBold;
}
}
function findItalic( $sItalic ){
} else {
return $sItalic;
}
}
function findUnderline( $sUnderline ){
if( preg_match ( $this->regUnderline, $sUnderline ) ){ } else {
return $sUnderline;
}
}
function findUrl( $sUrl ){
if ( preg_match_all ( $this->regUrl, $sUrl, $matches, PREG_SET_ORDER
) ){ for($i = 0; $i < count($matches); $i++){ $all = $matches[$i][0];
$url = $matches[$i][2];
$anchor = $matches[$i][3];
$sUrl = str_replace( $all,'<a href="'. $url .'">'. $anchor .'</a>',$sUrl ); }
return $sUrl;
} else {
return $sUrl;
}
}
/*
function findImage(){
if ( preg_match_all ( $this->regImage, $this->text, $matches, PREG_SET_ORDER ) ){
echo'<pre>';
print_r($matches);
echo'</pre>';
} else {
return $this->text;
}
}
*/
}
$bbCode = new bbCode;
$bbCode->setString( $_GET['text'] );
echo $bbCode->changeCode(); ?>
Ten post edytował dyktek 10.05.2006, 13:54:36