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

  • Home
  • SEARCH
  • 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 9017435
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T04:16:30+00:00 2026-06-16T04:16:30+00:00

I have written a module for a PHP IRC bot which uses a database

  • 0

I have written a module for a PHP IRC bot which uses a database for saving which nicks are “linked” to a Wikipedia account. To do this, I have the following code:

$pudb_wnas = file('cache.ucb');
foreach ($pudb_wnas as $lineNumber => $line) {
    if (preg_match("/" . p_chars($ex[4]) . "~!/i", $line) != false) {
        $found = true;
        break;
    }
}
if ($found) {
    echo "!!!!!!!!!!!!!!!!FOUND!!!!!!!!!!!!!!!!!!\n";
    $lines = file('cache.ucb', FILE_IGNORE_NEW_LINES);
    $wnas_bu = $lines[$lineNumber];                                                                                                                                            
    $lines[$lineNumber] = trim($wnas_bu) . "~!" . $mask[0];                                                                                                                    
    file_put_contents('cache.ucb', implode("\n", $lines));                                                                                                                     
} else {
    $udb_wnas = fopen("cache.ucb", "a+");
    fwrite($udb_wnas, "\n" . p_chars($ex[4]) . "~!" . $mask[0]);
    fclose($udb_wnas);
}

The p_chars function, alongside with dp_chars, is a custom function to add or remove backslashes to some special characters:

function p_chars( $text ) {
    $m_text = str_replace("(", "\(", $text);
    $m_text = str_replace(")", "\)", $m_text);
    return $m_text;
}

// Función para descodificar p_chars
function dp_chars( $text ) {
    $m_text = str_replace("\(", "(", $text);
    $m_text = str_replace("\)", ")", $m_text);
    return $m_text;
}

The cache.ucb file (which is really nas.udb, but that’s another story) contents are located here. You can also see the full code here.

The variable $ex[4], in this context, means the argument passed to the %nas command, which is used from IRC like this: %nas Test.

When you call the command, it searches on the cache.ucb file for a line starting with $ex[4]."~!". I use ~! as a separator. For example, if the command arguments were %nas Testing, it’d search for Testing~!. If it founds the line, it replaces it with itself plus "~!".$mask[0]. $mask[0] is the nickname of the user who called the command.

If it doesn’t find the line, it’ll add a new one following this structure: $ex[4]~!$mask[0]. So, as an example, if Bousie did %nas Testing, it would search for Testing~!. Assuming the line was Testing~!Test, it would replace it with Testing~!Test~!Bousie. Else, it’d add the line Testing~!Bousie.

The problem is that, if Bousie did %nas UnRar, it’d work properly. But if Bousie did %nas I(L)Verano, it’d add a new line. But there’s already the I(L)Verano line. Note that it should convert the I(L)Verano argument to I\(L\)Verano before sarching it, so I don’t know what I’m doing wrong on this code.

You’d really help me telling me what I’m doing wrong. Oh, and I tried with lots of codes I saw here, I tried mixing them and… Perhaps the problem is on the p_chars and dp_chars functions? I can’t see it, though!

  • 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-16T04:16:31+00:00Added an answer on June 16, 2026 at 4:16 am

    All you need is

    $file = "cache.ucb";
    $ex[4] = "I\(L\)Verano";
    $nick = "Bousie";
    $pudb_wnas = file($file, FILE_IGNORE_NEW_LINES);
    
    var_dump($pudb_wnas); // before
    foreach ( $pudb_wnas as $k => &$line ) {
        preg_match(sprintf("/^%s~/", preg_quote($ex[4])), $line) and $line = sprintf("%s~!%s", $line, $nick);
    }
    var_dump($pudb_wnas); // after
    file_put_contents($file, implode(PHP_EOL, $pudb_wnas));
    

    Before

    array (size=4)
      0 => string 'UnRar~!Catbuntu' (length=15)
      1 => string 'MistrX~!MRX' (length=11)
      2 => string 'I\(L\)Verano~!ILVerano' (length=22)
      3 => &string '-jem-~!jem-' (length=11)
    

    After

    array (size=4)
      0 => string 'UnRar~!Catbuntu' (length=15)
      1 => string 'MistrX~!MRX' (length=11)
      2 => string 'I\(L\)Verano~!ILVerano~!Bousie' (length=30)  // works perfectly 
      3 => &string '-jem-~!jem-' (length=11)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a large module written in JS which uses Canvas to draw and
I have a PHP module written in C++, which relies on a C++ library
I have written one module in cpp which uses openssl for SSL communication. I
Need assistance with the pexpect module I have written a simple code which would
have written this little class, which generates a UUID every time an object of
I have written a Python C module (just ffmpeg.c which depends on some FFmpeg
I have written some code which works without errors. The code uses MySQLdb for
I have written a Python module which contains functions that return arrays. I want
I have written a Linux kernel module, which I included in a kernel downloaded
I have written a module in python which performs some function. I then created

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.