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

  • Home
  • SEARCH
  • 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 7769637
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T16:12:30+00:00 2026-06-01T16:12:30+00:00

Hey guys i’m using this plugin from Hawkee. Its like twitter where you can

  • 0

Hey guys i’m using this plugin from Hawkee. Its like twitter where you can @mention someone. I’m having trouble with the output. This method:

updateHidden: function() {
        var trigger = this.options.trigger;

        var contents = this.element.val();
        for(var key in this.id_map) {
            var regex = trigger+key;
            regex = regex.replace(/[!@#\$%\^&\*\(\)\+=-\[\]\\';,\.\/\{\}\|":<>\?~_]/g, '\\$&');
            regex = new RegExp(regex, "g");
            //contents = contents.replace(regex, trigger+'['+this.id_map[key]+']');
            //I changed the code above to:
            contents = contents.replace(regex, '@[' + this.id_map[key] +':' + key + ']');
        }
        $(this.options.hidden).val(contents);
    }

The code above will be outputted to a hidden tag affecting its value wherein

Outputs: @[123:peterwateber] //Format is @[].

I’m using PHP as my back end. My problem is I wanna convert the output to

<a href="www.something.com/profile?pid=123">peterwateber</a>

I have a big problem with the codes here since I’m not good at RegEx. I have come up with the code:

    //THIS CODE SHOULD GET 1234,peterwateber,88,hi.

    $string = "@[1231:peterwateber] sdfsdfsdfsdfsdfsdf@[88:hi]sddsf";
    preg_match_all("^\[(.*?)\]^",$string,$matches,PREG_PATTERN_ORDER);
    foreach ($matches[1] as $match) {
        echo $match.'<br/>'; //outputs 1231:peterwateber, 88:hi
    }

    preg_match_all("^\[([\w\d]+):(.*?)\]^",$string,$aw,PREG_PATTERN_ORDER);
    foreach ($aw[1] as $match) {
        echo $match.'<br/>'; //sad to say this code outputs the text '1231 and 88'
    }

Moreso, to be able to get the output I have this form:

<form class="form-horizontal" data-post="request" method="post">
  <div class="control-group boxTextAreaHolder">
    <textarea placeholder="What are you thinking?" class="UITextarea" title="What are you thinking?" name="statuspost" id="statuspost" tag-status="this"></textarea>
    <input type="hidden" name="tags" id="tag-post" />
  </div>
</form>

When submitted the output will be processed to this function. This function does not allow any htmlspecialchars and detects a url like "http://stackoverflow.com"

private static function validate_text($text = '') {
    // This method is used internally as a FILTER_CALLBACK
    if (mb_strlen($text, 'utf8') < 1)
        return false;
    // Encode all html special characters (<, >, ", & .. etc) and convert
    //$str = nl2br(htmlspecialchars($text));
    $str = htmlspecialchars($text);
    // the new line characters to <br> tags:
    // Remove the new line characters that are left
    $str = str_replace(array(chr(10), chr(13)), '', $str);
    $text = preg_replace('#(script|about|applet|activex|chrome):#is', "\\1:", $str);
    $ret = ' ' . $text;
    $ret = preg_replace("#(^|[\n ])([\w]+?://[\w\#$%&~/.\-;:=,?@\[\]+]*)#is", "\\1<a href=\"\\2\" target=\"_blank\">\\2</a>", $ret);
    $ret = preg_replace("#(^|[\n ])((www|ftp)\.[\w\#$%&~/.\-;:=,?@\[\]+]*)#is", "\\1<a href=\"http://\\2\" target=\"_blank\">\\2</a>", $ret);
    $ret = preg_replace("#(^|[\n ])([a-z0-9&\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)*[\w]+)#i", "\\1<a href=\"mailto:\\2@\\3\">\\2@\\3</a>", $ret);
    //$ret = preg_replace("#^*@([)([0-9-])(])#is", "\\1<a href=\"http://\\2\" target=\"_blank\">\\2</a>", $ret);
    $ret = substr($ret, 1);
    return $ret;
}

The problem now is that I don’t know how to convert @[1234:peterwateber] to **<a href="www.something.com/profile?pid=123">peterwateber</a>** and how to exclude anchor tags from htmlspecialchars

  • 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-06-01T16:12:31+00:00Added an answer on June 1, 2026 at 4:12 pm

    Regular expression to take 1231 – peterwateber and 88 – hi is

    preg_match_all("#@\[(\w+)\:(\w+)\]#', $str);
    

    It depends on what kind of characters do you have in your input string. \w assumes you have only "word" characters (letters and digits).

    $hidden_input = '@[123:web]hello world!';
    
    preg_match('#@\[(\w+)\:(\w+)\]\s*(.*)$#', $hidden_input, $m);
    
    echo '<a href="'.m[1].'">'.$m[2].'</a>'.$m[3];
    
    
    
    function validate_text($text = '') {
        // This method is used internally as a FILTER_CALLBACK
        if (mb_strlen($text, 'utf8') < 1)
            return false;
        // Encode all html special characters (<, >, ", & .. etc) and convert
        //$str = nl2br(htmlspecialchars($text));
        $str = htmlspecialchars($text);
        // the new line characters to <br> tags:
        // Remove the new line characters that are left
        $str = str_replace(array(chr(10), chr(13)), '', $str);
        $text = preg_replace('#(script|about|applet|activex|chrome):#is', "\\1:", $str);
        $ret = ' ' . $text;
        $ret = preg_replace("#(^|[\n ])([\w]+?://[\w\#$%&~/.\-;:=,?@\[\]+]*)#is", "\\1<a href=\"\\2\" target=\"_blank\">\\2</a>", $ret);
        $ret = preg_replace("#(^|[\n ])((www|ftp)\.[\w\#$%&~/.\-;:=,?@\[\]+]*)#is", "\\1<a href=\"http://\\2\" target=\"_blank\">\\2</a>", $ret);
        $ret = preg_replace("#(^|[\n ])([a-z0-9&\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)*[\w]+)#i", "\\1<a href=\"mailto:\\2@\\3\">\\2@\\3</a>", $ret);
        //$ret = preg_replace("#^*@([)([0-9-])(])#is", "\\1<a href=\"http://\\2\" target=\"_blank\">\\2</a>", $ret);
        $ret = substr($ret, 1);
        return $ret;
    }
    
    var_dump(validate_text('@[123:peterwateber] fsdfsdfdsf'));
    

    gives string(30) "@[123:peterwateber] fsdfsdfdsf"

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

Sidebar

Related Questions

Hey guys. This is a follow-on from this question : After getting the right
hey guys, i was using Json dll in my project from quite sometime now
Hey guys I'm tired and can't figure this one out so any help would
hey guys I have the follow code in js: $(document).ready(function(){ $(.replyLink).click(function(){ $(#form-to-+this.id).html(htmlForm()).toggle(500); return false;
Hey guys i want to use the jquery Autocomplete plugin and instead of separating
Hey guys I am making a terminal application using Swing and Apache Commons. I
Hey Guys I've been struggling with this for the last hour and pouring over
Hey guys I just noticed that my join statement here SELECT * FROM reports
Hey guys I can't seem to get the syntax here right, I'm just trying
Hey guys! I have this little problem: I have one ViewController which adds 2

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.