php-windows Digest 12 Apr 2005 11:21:31 -0000 Issue 2630
Topics (messages 25824 through 25831):
replacing file contents
25824 by: Aidal
25825 by: Luis Moreira
25826 by: Kevin Smith
25827 by: M. Sokolewicz
25828 by: Luis Moreira
25829 by: Aidal
25830 by: Aidal
Lasted updated using PHP
25831 by: S.D.Price
Administrivia:
To subscribe to the digest, e-mail:
[EMAIL PROTECTED]
To unsubscribe from the digest, e-mail:
[EMAIL PROTECTED]
To post to the list, e-mail:
[email protected]
----------------------------------------------------------------------
--- Begin Message ---
Hi NG.
I'm having trouble searching through a file and swapping specific phrases
with other phrases.
I'm opening a html-file and i wish to replace "index2.php?someVar=SomeValue"
with somthing else but I can't get this to work properly.
first i open the html file and read all it's contents into a var... let's
call that one $file_contents for this example.
I'm currently trying using:
$altered_file_contents =
eregi_replace("index2.php?someVar=SomeValue","somevar_somevalue.html",
$file_contents);
Then I delete the file i opened, create a new one with the same name and
write the $altered_file_contents into it and close it.
But when I open it and check the line numbers that should have been altered,
they haven't been toutched at all, they still show the first link.
What am I doing wrong?
Why aren't eregi_replace() doing what I think it should?
Please help...
/Aidal
--- End Message ---
--- Begin Message ---
Hi
I, for one, have never done this, but if you are working with html
files, I suppose you open it with your browser ?
Have you cleared the cache, or at least forced the browser to
re-open the file ?
If you edit the file after the change using a text editor, do you
see the changes, or not ?
Luis
Aidal wrote:
Hi NG.
I'm having trouble searching through a file and swapping specific phrases
with other phrases.
I'm opening a html-file and i wish to replace "index2.php?someVar=SomeValue"
with somthing else but I can't get this to work properly.
first i open the html file and read all it's contents into a var... let's
call that one $file_contents for this example.
I'm currently trying using:
$altered_file_contents =
eregi_replace("index2.php?someVar=SomeValue","somevar_somevalue.html",
$file_contents);
Then I delete the file i opened, create a new one with the same name and
write the $altered_file_contents into it and close it.
But when I open it and check the line numbers that should have been altered,
they haven't been toutched at all, they still show the first link.
What am I doing wrong?
Why aren't eregi_replace() doing what I think it should?
Please help...
/Aidal
--- End Message ---
--- Begin Message ---
Hi,
It's none of that.
I suspect that the problem lies with the "?" question mar and the
full-stop. If you look up what the question mark and full-stop means in
an expression, you will find the answer to your problem. Basically you
need to escape the question mark, so it is not evaluated as part of the
expression, but as an absolute value.
So, it should be as follows:
$altered_file_contents =
eregi_replace("index2\.php\?someVar\=SomeValue","somevar_somevalue.html",
$file_contents);
Also, this will only work if the whole of the string is on one line, if
the HTML code is wrapped onto two lines, then you have a problem.
Obviously, there are workarounds, but for now try the above.
You may also want to look at preg_ as this is a more efficient mehtod of
regexp's.
Regards,
Kevin Smith
Luis Moreira wrote:
Hi
I, for one, have never done this, but if you are working with html
files, I suppose you open it with your browser ?
Have you cleared the cache, or at least forced the browser to
re-open the file ?
If you edit the file after the change using a text editor, do you
see the changes, or not ?
Luis
Aidal wrote:
Hi NG.
I'm having trouble searching through a file and swapping specific
phrases with other phrases.
I'm opening a html-file and i wish to replace
"index2.php?someVar=SomeValue" with somthing else but I can't get
this to work properly.
first i open the html file and read all it's contents into a var...
let's call that one $file_contents for this example.
I'm currently trying using:
$altered_file_contents =
eregi_replace("index2.php?someVar=SomeValue","somevar_somevalue.html",
$file_contents);
Then I delete the file i opened, create a new one with the same name
and write the $altered_file_contents into it and close it.
But when I open it and check the line numbers that should have been
altered, they haven't been toutched at all, they still show the first
link.
What am I doing wrong?
Why aren't eregi_replace() doing what I think it should?
Please help...
/Aidal
--- End Message ---
--- Begin Message ---
why are you using regexp-functions anyway? there's /absolutely/ no need
for them in your case. I can only see disadvantages:
1 - they use more memory than str_replace
2 - they're slower than str_replace
3 - they're more complicated than str_replace
Simply use str_replace, and it'll work just fine; use a regexp and
you'll need to escape characters and other weird things like that.
- tul
Kevin Smith wrote:
Hi,
It's none of that.
I suspect that the problem lies with the "?" question mar and the
full-stop. If you look up what the question mark and full-stop means in
an expression, you will find the answer to your problem. Basically you
need to escape the question mark, so it is not evaluated as part of the
expression, but as an absolute value.
So, it should be as follows:
$altered_file_contents =
eregi_replace("index2\.php\?someVar\=SomeValue","somevar_somevalue.html",
$file_contents);
Also, this will only work if the whole of the string is on one line, if
the HTML code is wrapped onto two lines, then you have a problem.
Obviously, there are workarounds, but for now try the above.
You may also want to look at preg_ as this is a more efficient mehtod of
regexp's.
Regards,
Kevin Smith
Luis Moreira wrote:
Hi
I, for one, have never done this, but if you are working with html
files, I suppose you open it with your browser ?
Have you cleared the cache, or at least forced the browser to
re-open the file ?
If you edit the file after the change using a text editor, do you
see the changes, or not ? Luis
Aidal wrote:
Hi NG.
I'm having trouble searching through a file and swapping specific
phrases with other phrases.
I'm opening a html-file and i wish to replace
"index2.php?someVar=SomeValue" with somthing else but I can't get
this to work properly.
first i open the html file and read all it's contents into a var...
let's call that one $file_contents for this example.
I'm currently trying using:
$altered_file_contents =
eregi_replace("index2.php?someVar=SomeValue","somevar_somevalue.html",
$file_contents);
Then I delete the file i opened, create a new one with the same name
and write the $altered_file_contents into it and close it.
But when I open it and check the line numbers that should have been
altered, they haven't been toutched at all, they still show the first
link.
What am I doing wrong?
Why aren't eregi_replace() doing what I think it should?
Please help...
/Aidal
--- End Message ---
--- Begin Message ---
FYI
This script
<?php
$body = "Test string xpto replace";
echo $body . "<br>";
$body = eregi_replace("xpto", "before", $body);
echo $body . "<br>";
?>
works and produces this output
Test string xpto replace
Test string before replace
Luis
Luis Moreira wrote:
Hi
I, for one, have never done this, but if you are working with html
files, I suppose you open it with your browser ?
Have you cleared the cache, or at least forced the browser to
re-open the file ?
If you edit the file after the change using a text editor, do you
see the changes, or not ?
Luis
Aidal wrote:
Hi NG.
I'm having trouble searching through a file and swapping specific
phrases with other phrases.
I'm opening a html-file and i wish to replace
"index2.php?someVar=SomeValue" with somthing else but I can't get
this to work properly.
first i open the html file and read all it's contents into a var...
let's call that one $file_contents for this example.
I'm currently trying using:
$altered_file_contents =
eregi_replace("index2.php?someVar=SomeValue","somevar_somevalue.html",
$file_contents);
Then I delete the file i opened, create a new one with the same name
and write the $altered_file_contents into it and close it.
But when I open it and check the line numbers that should have been
altered, they haven't been toutched at all, they still show the first
link.
What am I doing wrong?
Why aren't eregi_replace() doing what I think it should?
Please help...
/Aidal
--- End Message ---
--- Begin Message ---
DOH! Thanks Kevin for pointing out what should be the obvious !!! /hides
Ofcause, str_replace() I totally forgot about that one, maybe because I've
just been using eregi_replace() a lot lately, I dunno.
Anyway, everything works now as I should, thanks :o)
/Aidal
"M. Sokolewicz" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> why are you using regexp-functions anyway? there's /absolutely/ no need
> for them in your case. I can only see disadvantages:
> 1 - they use more memory than str_replace
> 2 - they're slower than str_replace
> 3 - they're more complicated than str_replace
>
> Simply use str_replace, and it'll work just fine; use a regexp and you'll
> need to escape characters and other weird things like that.
>
> - tul
> Kevin Smith wrote:
>> Hi,
>>
>> It's none of that.
>>
>> I suspect that the problem lies with the "?" question mar and the
>> full-stop. If you look up what the question mark and full-stop means in
>> an expression, you will find the answer to your problem. Basically you
>> need to escape the question mark, so it is not evaluated as part of the
>> expression, but as an absolute value.
>>
>> So, it should be as follows:
>>
>> $altered_file_contents =
>> eregi_replace("index2\.php\?someVar\=SomeValue","somevar_somevalue.html",
>> $file_contents);
>>
>> Also, this will only work if the whole of the string is on one line, if
>> the HTML code is wrapped onto two lines, then you have a problem.
>> Obviously, there are workarounds, but for now try the above.
>>
>> You may also want to look at preg_ as this is a more efficient mehtod of
>> regexp's.
>>
>> Regards,
>>
>> Kevin Smith
>>
>>
>> Luis Moreira wrote:
>>
>>> Hi
>>>
>>> I, for one, have never done this, but if you are working with html
>>> files, I suppose you open it with your browser ?
>>> Have you cleared the cache, or at least forced the browser to re-open
>>> the file ?
>>> If you edit the file after the change using a text editor, do you see
>>> the changes, or not ? Luis
>>>
>>>
>>> Aidal wrote:
>>>
>>>> Hi NG.
>>>>
>>>> I'm having trouble searching through a file and swapping specific
>>>> phrases with other phrases.
>>>>
>>>> I'm opening a html-file and i wish to replace
>>>> "index2.php?someVar=SomeValue" with somthing else but I can't get this
>>>> to work properly.
>>>>
>>>> first i open the html file and read all it's contents into a var...
>>>> let's call that one $file_contents for this example.
>>>>
>>>> I'm currently trying using:
>>>>
>>>> $altered_file_contents =
>>>> eregi_replace("index2.php?someVar=SomeValue","somevar_somevalue.html",
>>>> $file_contents);
>>>>
>>>> Then I delete the file i opened, create a new one with the same name
>>>> and write the $altered_file_contents into it and close it.
>>>>
>>>> But when I open it and check the line numbers that should have been
>>>> altered, they haven't been toutched at all, they still show the first
>>>> link.
>>>>
>>>> What am I doing wrong?
>>>> Why aren't eregi_replace() doing what I think it should?
>>>>
>>>> Please help...
>>>>
>>>> /Aidal
>>>>
>>>
--- End Message ---
--- Begin Message ---
Oops, seems I can't do anything right today.
It was M. Sokolewicz who had the solution but thanks to all who tried to
help me in my noobiest hour.
/Aidal
"Aidal" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> DOH! Thanks Kevin for pointing out what should be the obvious !!! /hides
>
> Ofcause, str_replace() I totally forgot about that one, maybe because I've
> just been using eregi_replace() a lot lately, I dunno.
> Anyway, everything works now as I should, thanks :o)
>
> /Aidal
>
>
> "M. Sokolewicz" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
>> why are you using regexp-functions anyway? there's /absolutely/ no need
>> for them in your case. I can only see disadvantages:
>> 1 - they use more memory than str_replace
>> 2 - they're slower than str_replace
>> 3 - they're more complicated than str_replace
>>
>> Simply use str_replace, and it'll work just fine; use a regexp and you'll
>> need to escape characters and other weird things like that.
>>
>> - tul
>> Kevin Smith wrote:
>>> Hi,
>>>
>>> It's none of that.
>>>
>>> I suspect that the problem lies with the "?" question mar and the
>>> full-stop. If you look up what the question mark and full-stop means in
>>> an expression, you will find the answer to your problem. Basically you
>>> need to escape the question mark, so it is not evaluated as part of the
>>> expression, but as an absolute value.
>>>
>>> So, it should be as follows:
>>>
>>> $altered_file_contents =
>>> eregi_replace("index2\.php\?someVar\=SomeValue","somevar_somevalue.html",
>>> $file_contents);
>>>
>>> Also, this will only work if the whole of the string is on one line, if
>>> the HTML code is wrapped onto two lines, then you have a problem.
>>> Obviously, there are workarounds, but for now try the above.
>>>
>>> You may also want to look at preg_ as this is a more efficient mehtod of
>>> regexp's.
>>>
>>> Regards,
>>>
>>> Kevin Smith
>>>
>>>
>>> Luis Moreira wrote:
>>>
>>>> Hi
>>>>
>>>> I, for one, have never done this, but if you are working with html
>>>> files, I suppose you open it with your browser ?
>>>> Have you cleared the cache, or at least forced the browser to
>>>> re-open the file ?
>>>> If you edit the file after the change using a text editor, do you
>>>> see the changes, or not ? Luis
>>>>
>>>>
>>>> Aidal wrote:
>>>>
>>>>> Hi NG.
>>>>>
>>>>> I'm having trouble searching through a file and swapping specific
>>>>> phrases with other phrases.
>>>>>
>>>>> I'm opening a html-file and i wish to replace
>>>>> "index2.php?someVar=SomeValue" with somthing else but I can't get this
>>>>> to work properly.
>>>>>
>>>>> first i open the html file and read all it's contents into a var...
>>>>> let's call that one $file_contents for this example.
>>>>>
>>>>> I'm currently trying using:
>>>>>
>>>>> $altered_file_contents =
>>>>> eregi_replace("index2.php?someVar=SomeValue","somevar_somevalue.html",
>>>>> $file_contents);
>>>>>
>>>>> Then I delete the file i opened, create a new one with the same name
>>>>> and write the $altered_file_contents into it and close it.
>>>>>
>>>>> But when I open it and check the line numbers that should have been
>>>>> altered, they haven't been toutched at all, they still show the first
>>>>> link.
>>>>>
>>>>> What am I doing wrong?
>>>>> Why aren't eregi_replace() doing what I think it should?
>>>>>
>>>>> Please help...
>>>>>
>>>>> /Aidal
>>>>>
>>>>
--- End Message ---
--- Begin Message ---
Hi can anyone help me I would like to use PHP to somehow record when a
user has changed the content of a web page e.g. Last updated 12 April
2005
Does anyone know how to do this?
Thanks
Steve
--- End Message ---