Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

mitismirza's avatar

search and replace strings with space in php

hey guys, i have this strign

 [8019](+) setinterfacevar=yes [8020](+) setinterfacevar=yes [8021](+) setinterfacevar=yes [8022](+) setinterfacevar=yes 

for example i want to search this:

[8019](+) setinterfacevar=yes

and delete it.

i use str_replace for find and replace it with '' but it doesnot find

 [8019](+) setinterfacevar=yes 

and it can just find

 [8019](+)

or

setinterfacevar=yes 

.

i test strpos but it is do the same.

how can i do that? thanks.

0 likes
3 replies
mitismirza's avatar

@REALRANDYALLEN - thanks for replay.

the php version i'm usig is 5.4.12.

this is my code :


    // delete from .conf file
   // for example $survey_queue is 8001
    $res  = $conn->query("SELECT * FROM settings WHERE id = $id");
    $row  = $res->fetch_assoc();
    $survey_queue = $row['survey_queue'];
    $conf  = "[$survey_queue](+)
    setinterfacevar=yes
    ";
    $path_to_file = '../../etc/queues_post_custom.conf';
    $file_contents = file_get_contents($path_to_file);
    $file_contents = str_replace("$conf","",$file_contents);
    file_put_contents($path_to_file,$file_contents);

and this is the queues_post_custom.conf

queues_post_custom

and its content when i echo the content:

echo $file_contents;
 //is:
[8020](+) setinterfacevar=yes [8021](+) setinterfacevar=yes [8022](+) setinterfacevar=yes [8024](+) setinterfacevar=yes [8001](+) setinterfacevar=yes [8005](+) setinterfacevar=yes 

All I want is to remove for example


[8005](+)
setinterfacevar=yes

// or somthing else like that

thanks.

mitismirza's avatar

problem solved , my mistake was in spaces in search word.

1 like

Please or to participate in this conversation.