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 6085785
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:40:42+00:00 2026-05-23T11:40:42+00:00

I’m working on a social networking site. When sending a notification, you for example

  • 0

I’m working on a social networking site. When sending a notification, you for example could type [user:20:name] in the notification as a developer in the text you send. So say i send

“[user:20:name] commented on your [video:8:name,link] video”

it would show up as “Bob commented on your iOS 5 review video”.

So it would see user, see the user id and that i wanted the name, it would then do the work in the database it needs and replace [user:20:name] in the string with Bob.

For the video it would know i wanted the name for video 8 as a link. How would i parse something like this? I already know how to grab data from the database. Just stuck on this part. Any idea how?

One of the idea was to get each [markup] by its self, and do the parsing on each one, then str_replace it when i get the processed version of the markup.

Not sure how i would get each [markup] by it self.

  • 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-23T11:40:42+00:00Added an answer on May 23, 2026 at 11:40 am

    Not sure if this is too simple, it doesn’t deal with multiple tags in a string but you could try something like this as a starting point:

    <?php
    
    // the original string
    $str = 'User [user:20:name] did foo bar.';
    
    // find the tag
    preg_match('/(?<=\[)[a-z0-9:]+(?=\])/', $str, $tags);    
    
    // build a db query
    list($table, $id, $field) = explode(':', $tags[0]);
    $sql = sprintf('SELECT %s FROM %s WHERE id = %d', $field, $table, $id);
    
    // DB query... returns user 'Bob'
    $user = 'Bob';
    
    // replace the original tag with the user's name
    $output = preg_replace('/\[user:\d+:name\]/', $user, $str);  
    

    Update

    For multiple tags you could use preg_match_all() and then iterate over the $tags array, probably using the $table variable as a key to build an array of query data… you’d have to decide on the most efficient way to use this data to query your database, based on your database implementation. if you can use PDO prepared statements might be good. so would caching your output because you don’t want to preg match and replace all your output every time… or just perform this operation one time and store the output in the database.

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

Sidebar

Related Questions

I'm working with an upstream system that sometimes sends me text destined for HTML/XML
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but
I have a text area in my form which accepts all possible characters from
i got an object with contents of html markup in it, for example: string
I have a reasonable size flat file database of text documents mostly saved in
I'm parsing an XML file, the creators of it stuck in a bunch social

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.