/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] UBB or vB Code Replacement

Anyone have an example, to go in the following function, for handling the following type of replacement in a forum post?

[CODE]
Click [href=url]here[/href] to see the page.[/CODE]

[code=php]
function ubb_code_replacement($str)
{
…replacement…
return $str;
}[/code]

I’m familiar with preg_match_all, preg_replace, and str_replace but I’m thinking about efficiency in coding — so, am looking for ideas and suggestions in that area. Thanks.

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@temp_user123authorJul 08.2007 — Actually, now that I think about it further, perhaps a more difficult replacement is this:
<i>
</i>[refer=username]This is what he said:
[refer=othername]blahblahblah...[/refer]
Now, isn't that something?
[/refer]

Anyone have an example of that?
Copy linkTweet thisAlerts:
@temp_user123authorJul 08.2007 — Well, I've come up with something that is working -- for the moment. If anyone cares to jump in on how to improve this, feel froggy...
[code=php]
function ubb_code_replacement($str)
{
if ($c = preg_match_all('/]*)?]|[/quote]/i', $str, $matches)):
for ($x=0; $x<$c; ++$x):
if (IsEmpty($matches[1][$x])):
$quote = ':';
else:
$quote = ' by: <b>' . $matches[1][$x] . '</b>';
endif;
if (strpos($matches[0][$x], '/') !== false):
$str = str_replace($matches[0][$x], '</div></blockquote>', $str);
else:
$str = str_replace($matches[0][$x], '<blockquote><br>Quote' . $quote .
'<br><div style="border:1px inset; padding:5px 10px;">',
$str);
endif;
endfor;
endif;
return $str;
}[/code]
×

Success!

Help @temp_user123 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...