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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T20:05:08+00:00 2026-05-11T20:05:08+00:00

What I thought was going to be an easy implementation of two lines of

  • 0

What I thought was going to be an easy implementation of two lines of code and a function, turned out to be made of fail.

On my webpage, I want to be able to type [text]1[/text], and what it will do is pull the title of that ID.

function textFormat($text) {
    $raw = array(
        '\'\[text\](?P<id>.*?)\[/text\]\'is'
    );

    $out = array (
        '<a href="index.php?function=getData&reference=text&id=$1">' . getTextTitle() . '</a>'
    );

    preg_replace($raw, $out, $text);
    return $text;
}

function getTextTitle($id) {
     $sql = mysql_query("SELECT title FROM text WHERE id = $id");
     return mysql_result($sql);
}

So, here’s the lovely little problem: As one can tell, I’m calling a function with a numeric-titled variable, which works great in the quotation marks, but as we know, PHP doesn’t like that. So, I opted for a named group. Using $regs['id'] fails to work.

Am I doing something wrong?

Am I going about this the wrong way?

  • 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-11T20:05:09+00:00Added an answer on May 11, 2026 at 8:05 pm

    Well, you’re certainly doing it in a radically different way than I ever would, but I think something not too far off from what you’re attempting may possibly work. Try this:

    function textFormat($text) {
        $raw = array(
            '\'\[text\](?P<id>.*?)\[/text\]\'ise'
        );
        $out = array (
            '\'<a href="index.php?function=getData&reference=text&id=$1">\' . getTextTitle(\'$1\') . \'</a>\''
        );
        preg_replace($raw, $out, $text);
        return $text;
    }
    
    function getTextTitle($id) {
         $sql = mysql_query("SELECT title FROM text WHERE id = '" . mysql_real_escape_string($id) . "'");
         $res = mysql_result($sql);
         $row = mysql_fetch_array($res);
         return $row ? $row[0] : 'invalid ID';
    }
    

    Your original getTextTitle() would, unless something else is going on I’m not aware of, let anyone do anything they liked to your database via SQL injection, by the way. You’re welcome.

    Also, I don’t know what that (?P<id> noise is about in the regex, so I’m assuming it’s needed for some reason and leaving it alone. I do not know whether this is correct.

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

Sidebar

Related Questions

Man... thought using ASIO in Boost was going to be easy and intuitive. :P
I thought this would be an easy one for me to figure out (or
i thought that this was going to be an easy move as what i'm
I have a project that I thought was going to be relatively easy, but
I thought this was going to be easy, but it's turning into quite a
set dateformat dmy select isdate('31/1/2012') I thought by going into Change the format of
Initially I thought this was going to work, but now I understand it won't
I am going crazy now. Googled this, thought some kind of IDE bug. Maybe
Im new on this project and am going to write, what i thought was
I have a surprisingly basic question; I thought the answer was going to be

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.