Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 907173
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T16:30:36+00:00 2026-05-15T16:30:36+00:00

I need to do this : when a user insert a BBCode tag, with

  • 0

I need to do this :

when a user insert a BBCode tag, with preg_replace and regex i do some trasformation.

e.g.

function forumBBCode($str){
   $format_search=array(
      '#\[url=(.*?)\](.*?)\[/url\]#i'
   );

   $format_replace=array(
      '<a class="lforum" target="_blank" href="$1">$2</a>'
   );

   $str=preg_replace($format_search, $format_replace, $str);
   $str=nl2br($str);
   return $str;
}

now i want also this : when a user insert a normal text with a link, this must be trasformed too. i can’t do this trought preg_replace function, because if i write a code as

$format_search
'#(www\..*?)#i'

$format_replace
'<a class="lforum" target="_blank" href="$1">$1</a>'

it will convert the link 2 time (in the [url] and when the link is without this tag).

so i think to this function :

    function checkLinks($string) {
    $arrelab="";
    $arr=split(' |\r\n', $string);
    for($i=0; $i<sizeof($arr); $i++) {
        echo $i." - ".$arr[$i]."<br/>";
        if ((strpos($arr[$i], 'www.')!==false) or (strpos($arr[$i], 'http://')!==false) or (strpos($arr[$i], 'ftp://')!==false)) {
            if (strpos($arr[$i], '[url=')===false) {
                $arr[$i]='<a class="lforum" target="_blank" href="'.$arr[$i].'">'.$arr[$i].'</a>';
            }
        }

        $arrelab=$arrelab." ".$arr[$i];
    }
    return $arrelab;
}

the problem is that i need a split as for the newline, as for the empty space.
any help would be appreciated.

p.s. sorry for my bad english 🙂

cheers

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T16:30:37+00:00Added an answer on May 15, 2026 at 4:30 pm

    It’s easy to workaround with a lookbehind assertion.

    preg_replace('#(?<![>/"])((http://)?www.........)#im', '<a href="$1">$1</a>'
    

    Thus the regex will skip any URL enclosed in ” or > or preceeded by /
    It’s a workaround, not a solution.

    PS: target=”_blank” is user pestering. Cut it out.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 492k
  • Answers 492k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer There is no word boundary before ".net" because \b only… May 16, 2026 at 10:34 am
  • Editorial Team
    Editorial Team added an answer Without seeing your code, it's hard to answer other than… May 16, 2026 at 10:34 am
  • Editorial Team
    Editorial Team added an answer With VC10 the solution you linked to doesn't work -… May 16, 2026 at 10:34 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

All I need to do is have a form that does this: User enters
I have a dictionary in JSON form, like this: $user = { name: Mary
I have some logic whereby a graph of POCO entities need to be cloned
I have an InnoDB table containing users, like this: +--------------+-----------------------+ | user_id | name
I need to make something like google-analytics, I mean that it has to be
I have the following code I use to insert form data into a single
I have a question related to this one . I don't want to do
Is there any way to stop a running loop inside another method or insert
I'm a 2nd year ICT student. I never did PHP before this year and
Currently I have a service that uses a UserNamePasswordValidator to authenticate the client user.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.