Hi and I have the below php-gtk script but for some reason it is reporting the error "Not enough storage is available to process this command." in the command console but the application still loads. It only happens when I try to import a 1.75MB text file for processing. Does anybody know why regex and str replace on a 1.75MB file causes this error or how to increase its storage. Please advice.

<?php
ini_set('memory_limit','256M');
if (!class_exists('gtk')) {
    die("Please load the php-gtk2 module in your php.ini\r\n");
}
function func_generate() {
//reword button clicked.
return true;
}
function func_open() {
global $wnd, $filebox, $textareaBuffer,$text;
$fileselection = new GtkFileSelection('Open');
$fileselection->set_select_multiple(false);
$fileselection->complete('*.*');
$fileselection->hide_fileop_buttons();
$fileselection->show_all();
$fileselection->cancel_button->hide_all();
//$fileselection->history_pulldown->hide_all();
if ($fileselection->run() == Gtk::RESPONSE_OK) {
    if (@is_readable($fileselection->get_filename())) {
        $fileselection->hide_all();
        $filebox->set_text($fileselection->get_filename());
        $text=str_replace(array('(',')','  ','  '),array(' ( ',' ) ',' ',' '),preg_replace('#[^a-zA-Z0-9\'\(\) ]#',' ',file_get_contents($fileselection->get_filename())));
        /*$text_tmp=file_get_contents($fileselection->get_filename());
        $text_tmp=str_split($text_tmp,1);
        $arr=array();
        $chars=array('a'=>true,'b'=>true,'c'=>true,'d'=>true,'e'=>true,'f'=>true,'g'=>true,'h'=>true,'i'=>true,'j'=>true,'k'=>true,'l'=>true,'m'=>true,'n'=>true,'o'=>true,'p'=>true,'q'=>true,'r'=>true,'s'=>true,'t'=>true,'u'=>true,'v'=>true,'w'=>true,'x'=>true,'y'=>true,'z'=>true,'A'=>true,'B'=>true,'C'=>true,'D'=>true,'E'=>true,'F'=>true,'G'=>true,'H'=>true,'I'=>true,'J'=>true,'K'=>true,'L'=>true,'M'=>true,'N'=>true,'O'=>true,'P'=>true,'Q'=>true,'R'=>true,'S'=>true,'T'=>true,'U'=>true,'V'=>true,'W'=>true,'X'=>true,'Y'=>true,'Z'=>true,'('=>true,')'=>true,'\''=>true,' '=>true);
        for ($i=0;$i<count($text_tmp);$i++) {
            if (isset($chars[$text_tmp[$i]])) {
                if (($text_tmp[$i]=='(' || $text_tmp[$i]==')') && $text_tmp[($i-1)]!=' ') {
                    $arr[]=' ';
                    }
                $arr[]=$text_tmp[$i];
                if (($text_tmp[$i]=='(' || $text_tmp[$i]==')') && $text_tmp[($i+1)]!=' ') {
                    $arr[]=' ';
                    }
                }
            }
        unset($text_tmp);
        $text='';
        foreach($arr AS $val) {
        $text.=$val;
        }*/
        $textareaBuffer->set_text($text);
        } else {
        self::open();
        }
    }
return true;
}
 
$wnd = new GtkWindow();
$wnd->resize(875,700);
$wnd->set_title('Reworder bot - by cwarn23');
$wnd->connect_simple('destroy', array('gtk', 'main_quit'));
 

// Create a new buffer and a new view to show the buffer.
$textareaBuffer = new GtkTextBuffer();
$textarea       = new GtkTextView();
 
// Add some text to the buffer.
$textareaBuffer->set_text('');
 
// Add the buffer to the view and make sure no one edits the text.
$textarea->set_buffer($textareaBuffer);
$textarea->set_editable(false);
 
$viewPort= new GtkViewPort();
$textView= new GtkScrolledWindow();

$viewPort->add($textarea);
$textView->add($viewPort);

$Vbox= new GtkTable(30,30);
$Vbox->attach($textView,0,30,1,30,Gtk::FILL|Gtk::EXPAND);

$filebox= new GtkEntry();
$Vbox->attach($filebox,1,29,0,1,Gtk::FILL|Gtk::EXPAND);

$submit= new GtkButton('Reword Text');
$submit->connect_simple('clicked','func_generate');
$Vbox->attach($submit,0,1,0,1,Gtk::FILL|Gtk::EXPAND);
$filebtn= new GtkButton('Select File');
$filebtn->connect_simple('clicked','func_open');
$Vbox->attach($filebtn,29,30,0,1,Gtk::FILL|Gtk::EXPAND);
$wnd->add($Vbox);


 
$wnd->show_all();
Gtk::main();
?>

Found the problem. The following line is the bug.

$textareaBuffer->set_text($text);

The buffer can't hold more than 1024 characters. Does anybody know how to insert more?

Solved. Downloaded the latest version of php-gtk and the bug is fixed.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.