...

View Full Version : Setting [img][/img]



Why_me
08-13-2008, 03:03 PM
I am having a lot of problems with this code When I try to use the
it is showing the in test and the url of the image instead of just showing the image I cant figure it out heres the code

$quote2 = str_replace("
","<center>", $quote2);
$quote2 = str_replace("","</center>", $quote2);
$begin = "";
$end = strtolower($quote2);
while( !empty( $end ) ) {
$p = strpos( strtolower( $end ), "");
if( $p === FALSE ) {
$begin = $begin . $end;
$end = "";
} else {
$begin = $begin . substr( $end, 0, $p );
$end = substr( $end, $p );

$p = strpos( $end, "" );
if( $p === FALSE ) {
$p = strlen( $end );
}
$p = ($p - 5);

$url = substr( $end,5, $p );

list($width, $height, $type, $attr) = @getimagesize( $url );
if ($width > 450) {
$begin = $begin . "<center><img width=450 src=\"$url\"><br/></center>";
} else {
$begin = $begin . "<center><img % src=\"$url\"></center>";
}
$end = substr( $end, strlen( $url ) );
$end = substr( $end,5);
}
}
// $quote2 = $begin;
$quote2 = str_replace("","", $quote2);
$quote2 = str_replace("[/IMG]","", $quote2);

Why_me
08-13-2008, 06:49 PM
I have fixed it

Fou-Lu
08-13-2008, 07:28 PM
Consider replacing BBCode style tags with regex instead. str_replace is faster than preg_replace, but when you need to add several lines of logic behind the str_replace it begins to take significantly more time and effort to create.
The problem with str_replacements is its lack of control. With a preg you can ensure that both a start and an end tag have been supplied, which will keep it from breaking you're original html code.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum