Grow your CSS skills. Land your dream job.

If status contains @tag then..?

  • # February 11, 2012 at 5:26 pm

    All I need is a PHP scripts that detects if the variable “comment” includes any ” @username ” – and then get that username without the “@” :)

    # February 12, 2012 at 1:11 pm

    $words = explode(" ",$comment);
    foreach ($words as $word) {
    $match = preg_match("/B@[^B]+/",$word,$matches);
    if ($match==1) {
    $username = substr($matches[0],1);
    echo $username;
    }
    }
    # February 12, 2012 at 3:03 pm

    Thank’s. I did it a bit different:


    < ?php
    $comment = "We all know @Schart does like cupcakes";

    if(strstr($comment, '@')){
    $tagafter = strstr($comment, "@");
    /* TAGAFTER = @Schart does like cupcakes */

    $arr = explode(' ', trim($tagafter));
    $tag = $arr[0];
    /* TAG = @Schart */

    $newtag = str_replace('@', '', $tag);
    /* NEWTAG = Schart */

    echo($newtag);
    ?>

    # February 12, 2012 at 7:43 pm

    Your method will only find the first username in a comment though.

    # February 18, 2012 at 7:07 am

    That is true :)

    # August 12, 2012 at 11:32 am

    @bungle Long time since this post was active, but I just want to say thank you again, since I went back to this post now after re-making the website and I use this for notifications when someone is tagged. I used your version this time, so much better.

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".