Write multiple backslashes
[email protected] (Danny)
| Newsgroups | php.general |
|---|---|
| Message-ID | <[email protected]> |
Hi, I have a file in which I need to interchange two regular expressions every hour depending on what data will be processed. In other words, I will replace the one regular expression with the other (they are never together in the same file). This file is a configuration file for attatched hardware (not written by myself but by the hardware manufacturer). Below is what it should look like in the file: IGNORE_TMP=^()$ or IGNORE_TMP=^(\\*.*\\*)$" (Yes, this one has 2 backslashes) Now, the first regular expression I can write to the file like this with no problems: $first_regexp = "/IGNORE_TMP=\\^\\(\\)\\$/" ; which will give me: IGNORE_TMP=^()$. However, I cannot seem to get it right to write the second regular expression correctly to get 2 backlashes. I can get 1 with no problem: $second_regexp = "IGNORE_TMP=^(\\*.*\\*)$" ; ### Here is just the rest of the code for reference ### $block_file = file_get_contents ( $tmp_file ) ; $block_regexp = preg_replace ( $old_block, $new_block, $block_file ) ; file_put_contents ( $tmp_file, $block_regexp ) ; $remove_blank_lines = exec ( 'sed -i "/^[[:space:]]*$/d" /etc/scripts/motor_control/temperature.conf' ) ; ####################################################### Any pointers? Thank you Danny