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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T20:51:11+00:00 2026-06-04T20:51:11+00:00

I use preg_replace() alot but I’m not a genius at it. If I start

  • 0

I use preg_replace() alot but I’m not a genius at it.

If I start up a function and deliberately key in all the smilies that I want to use e.g.

<?php
function parse_emotes($body){
    $body = preg_replace("#\:p#i", "<img src='images/emotes/tongue.png' alt=':p' title=':p' />", $body);
    //they continue like i said
    return $body;
}
?>

but today I tried to change it up and use mysql to let me just insert and delete them as I please without playing in my code, but when I tried it, it only throws

Warning: preg_replace() [function.preg-replace]: No ending delimiter
‘#’ found in PATH/TO/FILE.php on line 226

Here is the code I used the first time:

<?php
function parse_emotes($body){
    while($row = $db->Query("SELECT * FROM emotes", 3)) {

        return $body = preg_replace($row['regex'], "<img src='images/emotes/" . $row['src'] . "' alt='" . $row['alt'] . "' title='" . $row['alt'] . "' />", $body);
    }
}
?>

That didn’t work, and yes the regex row included the delimiters so it would output #\:p#

I got the same error as stated before and then I tried to take the #s out of the data in MySQL and just changed preg_replace as follows

preg_replace('#' . $row['regex'] . '#i', .......)

and it still does not like it? I have also tried assigning:

$regex = $row['regex'];
preg_replace("#$regex#i");

Guess what? Still a no. Any help with where to go with this is very appreciated.

  • 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-04T20:51:14+00:00Added an answer on June 4, 2026 at 8:51 pm

    Since people are still downvoting this topic. @salathe was correct in the questions comments (returning in the loop.. Ooops).

    but here is the answer:

    $emotes = $db->select(['regex', 'class'])->from("emotes")->execute();
    while ($emote = $db->fassoc($emotes)) {
        $body = preg_replace("#{$emote['regex']}#i", "<i class='sprite-emote {$emote['class']}'></i>", $body);
    }
    /* ...other parsing... */
    return $body;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having trouble with preg_replace and I'm not sure that I use correct function.
I want to use preg_replace for combination of '[', ']' and '/' but I
I am trying to use preg_replace function to parse this table in a Html
With PHP, I'd like to use a preg_replace() filter for passwords such that the
I'm trying to use preg_match to extract info from href=domain.com/subdir/?key=value The info I want
I have well-formed xml documents into string variables. I want to use preg_replace to
Is there any reason why I can't use preg_replace inside a static function? when
I need a quick REGEX to use with preg_replace() in PHP that will remove
I want to use preg_replace_callback to replace all instances of a custom tag with
How to use preg_replace, remove all the links with class=country and remain the links'

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.