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
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>"
);

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.