Jump to content

Recommended Posts

Hello,

 

I'm working on some sort of BB code system, and I'm having a little bit of trouble with the colouring on font.

 

[color=??????][/color]

 

I need preg_match to check if a string has the code above, and, more importantly, return the value of ??*??*?? (without the *)

 

Any help is, as always, much appreciated.

Link to comment
https://forums.phpfreaks.com/topic/82520-solved-using-preg_match-to-get-a-value/
Share on other sites

Ok, i figured part of it out:

 

if ( preg_match( '/\[color\=(.*?)\](.*?)\[\/color\]/is', $entry, $matches ) )

 

When i use 'print_r( $matches )', it works great. But if I used $match[0][0], it only returns the first character of what I want.

 

Any help?

ahh use preg_match_all

<?php
$entry = "[color=000000]some text[/color] and [color=FF0000]other text[/color]";

preg_match_all('%\[color\=(.*?)\](.*?)\[\/color\]%si', $entry, $result, PREG_SET_ORDER);
foreach($result as $r)
{
echo "color: ".$r[1]; //Color
echo "<br>text: ".$r[2]; //text
echo "<br>---<br>";
}

?>

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.