Jump to content

[SOLVED] preg_replace question


maxudaskin

Recommended Posts

I made a forum, and I decided that a quoting system was in order. I quietly edited the bbcode list and now I was wondering:

Can I make it multi-line? (See image 1 and 2)

Can I put a quote in a quote? (See image 3)

 

Image 1 Text

This is a quote test.
[quote]This is quoted text.[/quote]

This is a colour test.
[blue]The is blue.[/blue]
[red]This is red.[/red]

Current Project: [b]Debugging Quote System[/b]

 

Image 2 Text

This is a quote test.
[quote]This is quoted text.
This is a second line.[/quote]

This is a colour test.
[blue]The is blue.[/blue]
[red]This is red.[/red]

Current Project: [b]Debugging Quote System[/b]

 

Image 3 Text

This is a quote test.
[quote]This is quoted text.[quote]This is a quote inside a quote.[/quote][/quote]

This is a colour test.
[blue]The is blue.[/blue]
[red]This is red.[/red]

Current Project: [b]Debugging Quote System[/b]

 

Source Code (Amended)

<?php
$text = $posts['text'];
$message = preg_replace($find,$rplc,$text);
preg_match_all('/\[img\](.+?)\[\/img\]/', $text, $url);
$imagekeys = array_keys($url[1]);
for($i=0;$i<count($imagekeys);$i++){
    echo "<img src\"";
    print_r($url[$i][0]);
    echo "\" height=\"" . $height . "\" width=\"" . $width . "\" alt=\"We Cannot Find This Specified Image\" /><br />";
}
$message  = str_replace($smilies,$locations,$message);
$pattern = '%
(http://)? ### optional http:// prefix
(?(1)|www\.) ### require www. if there is no http://
\S+ ### gobble anything but white space
%x';

$message =  preg_replace_callback($pattern, 'clickable_short_url', $message); // Change URLs into links
echo nl2br($message);
?>

 

<?php

// BBCode

$find=array(
"/\[b\](.*)\[\/b\]/",
"/\[i\](.*)\[\/i\]/",
"/\[u\](.*)\[\/u\]/",
"/\[img\](.*)\[\/img\]/",
"/\[link\](.*)\[\/link\]/",
"/\[big\](.*)\[\/big\]/",
"/\[small\](.*)\[\/small\]/",
"/\[red\](.*)\[\/red\]/",
"/\[blue\](.*)\[\/blue\]/",
"/\[green\](.*)\[\/green\]/",
"/\[quote\](.*)\[\/quote\]/"
);


$rplc=array(
"<b>$1</b>",
"<i>$1</i>",
"<u>$1</u>",
"<img src='$1'/>",
"<a href='$1'>$1</a>",
"<h1>$1</h1>",
"<h4>$1</h4>",
"<font color='red'>$1</font>",
"<font color='blue'>$1</font>",
"<font color='green'>$1</font>",
"<div class='forumquote'>$1</div>"
);


?>

 

Style

.forumquote {
    text-align: left;
    background: #efefef;
    color: #333;
    border: 1px inset #333;
    font-family: "Courier New", Courier, monospace;
    padding: 5px;
    margin: auto;
    width: 90%;
    max-height: 200px;
    overflow: auto;
}

 

upl3593218650.jpg

Image 1

 

upl1921485662.jpg

Image 2

 

upl1478093032.jpg

Image 3

 

Link to comment
https://forums.phpfreaks.com/topic/111203-solved-preg_replace-question/
Share on other sites

try

$find=array(
"/\[b\](.*)\[\/b\]/",
"/\[i\](.*)\[\/i\]/",
"/\[u\](.*)\[\/u\]/",
"/\[img\](.*)\[\/img\]/",
"/\[link\](.*)\[\/link\]/",
"/\[big\](.*)\[\/big\]/",
"/\[small\](.*)\[\/small\]/",
"/\[red\](.*)\[\/red\]/",
"/\[blue\](.*)\[\/blue\]/",
"/\[green\](.*)\[\/green\]/",
//"/\[quote\](.*)\[\/quote\]/"
"/\[quote\]/",
"/\[\/quote\]/"
);


$rplc=array(
"<b>$1</b>",
"<i>$1</i>",
"<u>$1</u>",
"<img src='$1'/>",
"<a href='$1'>$1</a>",
"<h1>$1</h1>",
"<h4>$1</h4>",
"<font color='red'>$1</font>",
"<font color='blue'>$1</font>",
"<font color='green'>$1</font>",
//"<div class='forumquote'>$1</div>"
"<div class='forumquote'>",
"</div>"
);

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.