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

Related Questions

i need to convert this HQL: FROM Appointment a WHERE (a.group==null OR :user MEMBER
My program flow is like this: I need to sequential processing per user's request
User Story: Action for Facebook that has open graph object. For this I need
I need to build app with user messages (dialogs). I've solved this problem by
I need some additional functionality added to user_pass_submit. This must be added without changing
My user activity log looks something like this: Id, Username, Date I need to
My point is this. For test i need when user check chk1 the chk2
I need some help on how to set up this page. Let's say I
I need to tweak UiTextField behavior so that I can programmatically insert some asterisks
I have s MySQL database and I need to insert some specific data in

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.