Forum Moderators: coopster
For example.
I have links called foo.php throughout my document I want to change it to new.php how would I go about doing this using preg_replace and prevent myself from typing it manually throughout the document.
I have looked at php manual but it doesnt say how to do it throughout a document and not specific a named variable.
Thanx in advance ppl.
str_replace works like this right?
str_replace($search,$replace,$string);
but how do i use that when the $string is the whole page which is what it needs to search through to find foo.html and replace with new.php.
Omg im a junior member how did that happen w00t!
[edited by: Dilly at 2:32 pm (utc) on Sep. 18, 2007]
The reason why I don't use the replace all on a text editor is because i am looking to use this str_replace thinmy for the foo.html in a header.php include which will perform it on all the god knows how many pages of my website. Could you give me and example of how I would use those two functions with str_replace.
Cheers
It saying that file_get_contents undefined function so is there any other way without me having to upgrade my php.
I'm sure this is a common problem that people get sorted when they need to change hrefs throughout there website.
Otherwise I'll have to do it the hard way and find and replace all links throughout the files.
Please don't make me do it!
[edited by: Dilly at 3:50 pm (utc) on Sep. 18, 2007]
they are replacements for file_get_contents, the manual has good examples of how they are used
fread probably being the simplest
use fread to get the contents of the file into a var
use str_replace to swap the links
then fwrite the contents of the var back to the file
I would also suggest a backup before you do this
how many pages are we talking? You might be better off to change all those files to use an include for the header. This would save quite a bit of time in the future when you need to change the header.
and it's FREEWARE!
Google it guys its Baaaad!
[edited by: Dilly at 5:16 pm (utc) on Sep. 18, 2007]