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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:49:29+00:00 2026-05-25T19:49:29+00:00

again. I’m trying to go through a database table and replace all instances of

  • 0

again.
I’m trying to go through a database table and replace all instances of old BBCode (ie: [i:fs8d979]) and replace it with simple BBCode ([i]). However, I’m getting very confusing results.

$root_path = './';
include($root_path.'includes/common.php');

$posts = array();
$sql = 'SELECT post_id, post_text FROM posts';
$db->query($sql);
while($row = $db->fetch_assoc())
{
    $posts[]['id'] = $row['post_id'];
    $posts[]['text'] = $row['post_text'];
}

foreach($posts as $post)
{
    $regex = "/\[(\D)(\:[a-zA-Z0-9_]{1,})\]/";

    if(preg_match($regex, $post['text'], $matches))
    {
        $string = preg_replace('/'.$matches[2].'/', '', $post['text']);
        $sql = 'UPDATE posts SET post_text = "'.$string.'" WHERE post_id = '.$post['id'];
        $db->query($sql);
        echo $post['id'].'--Matched and replaced<br />';
    }
    else
    {
        echo $post['id'].'--No Match<br />';
    }
}
echo 'done';

when i run this script, I get output like this:

1302--No Match
--No Match
1303--No Match
--No Match
17305--No Match
--Matched and replaced
5532--No Match
--No Match
17304--No Match
--No Match
1310--No Match
--No Match

it would appear that the script is attempting to do everything twice, and I’m not sure why. The database fields are not getting updated either.
I’ve echoed everything out for debugging purposes, and all variables are set and everything looks like it should be working properly.
Any suggestions?

  • 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-25T19:49:30+00:00Added an answer on May 25, 2026 at 7:49 pm

    At the point in the code:

    while($row = $db->fetch_assoc())
    {
        $posts[]['id'] = $row['post_id'];
        $posts[]['text'] = $row['post_text'];
    }
    

    You are creating two entries in the array, one with the id, followed by the text.

    I think you want:

    while($row = $db->fetch_assoc())
    {
        $posts[] = array('id' => $row['post_id'], 'text' => $row['post_text']);
    }
    

    It would explain why each one is happening twice and nothing is changing.

    The debug was showing the wrong value too:

    echo $post['id'].'--Matched and replaced<br />';

    and the output was

    --Matched and replaced which showed no post id.

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

Sidebar

Related Questions

Again I apologize for a question that might be simple to all of you.
Again, I'm trying to make a simple program. It will read some kind of
Here we go again, the old argument still arises... Would we better have a
I'm trying to get into java again (it's been a few years). I never
Again with the soap. I am trying to build a header using soap4r that
Again, I am new to JPA & Hibernation. I am trying to use JPA
Again a simple thing. I have a stylesheet that parses XML and XSL files.
Once again I need some help. I'm working with a table that contains 3
Again I'm trying to wrap my head around Objective-C and Cocoa. So I've posted
again. I'm having more issues with my script entering info into my database. The

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.