I have an input named 'addcss', and a string that contains: $style = '\$addcss = "some text(multiline)"'; PHP: So I get this code: $addcss = $_POST['addcss']; to retrieve the value from a text area and then run: <? $style = preg_replace('(\$addcss = "#?((.*?))?#";)','\$addcss = "'.$addcss.'";',$style); ?> PHP: And it doesn't change, and I have been running this with several other values, and it works with all of them, and the only thing 2 differences are: 1. This one has a multiline value 2. The value is retrieved from a textarea - not an input. I am really stumped, Thanks BP
OK I have tried this with another textarea, and it is definetly multiline issues, I desperately need help with this as it is holding up the release of an entire script.... I have tried this: $style = preg_replace('#(\$addcss = "((.*?))?"; )#esim','\$addcss = "'.$addcss.'";',$style); PHP: Still no luck SO basically all I want is something to find and replace anything between " and " regardless whether its multiline or not.
Well I have recoded and now it is editing another PHP file: <?php $addcss = "Some text here, this string is multiline. And user submitted."; ?> PHP: And I want to replace it with a user defined variable retrieved from a textarea. The string is contained with the variable $style - which is file_get_contents(php file). I just need to change the text bettween: $addcss = " and " when the user edits the textarea and submits the form. Thanks, BP
Assuming that I understand what you're trying to do, this should work: $s = file_get_contents('myfile'); $s = preg_replace('/\$addcss = ".*[^\\\]"/s', '$addcss = "' . $new_str . '"', $s); PHP: where $new_str is the carefully sanitized value posted in the form. It appears that you are allowing people to post in values that will be executed as PHP code, which is of course extremely dangerous.
Well yes, but is for admin access only (which is fairly secure), and it doesn't really do anything but change variable values. Thanks, I'll test it out, BP EDIT: Kinda works. However it deletes everything in the file below the ";" at the end of that variable EDIT2: Got it working, thanks