Saturday, 15 January 2011

preg_replace to replace all instances of text in .php file -


I'm here and a full newbie. Sorry if this question is very basic, but I do not understand the best way to do it can.

I have a lot of .php files that contain various text placeholders. For example, in my .php file, I have something like this:

I like it and Stay there

Or a link,

  & lt; A href = "xcity_is_awesome.php" & gt;   

I thought that I can use some php code at the top of every page to preg_replace a page that says "xcity" or "xcity" with "mesti" or "mesti" Any examples of "will change respectively, respectively."

I can get it to work currently:

  & lt; ? Php $ xCity = "Mycity"; ? & Gt;   

As long as I change all versions of "xCity" in the document:

    

I know that there is a clever way of doing this, but like I said, I am completely new.

Can anyone help me? <

By using one of the examples given below, I can not seem to work for it.

I changed a couple in the document "xcity" to the variable "{{xcity}}"

This is my code in PHP code:

    

When I upload a file and preview it, the PHP text does not change. I'm sure I have to do something wrong :)


I am currently using Spencerje (bottom) suggestions:

    

Then use an echo statement to swap the variable:

    

I think PHP has a problem:

    

Now, I'm convinced that there are many php "commands" with each other in such a way that how can this be controlled?

Find and replace you - mostly in the IDE project, xCity to and . & lt ;? Php $ xCity = For prepending for "Mycity"; ? & Gt; , you can probably do this in any IDE which allows regex searches using / ^ / s (or something similar), although it is probably easy to add

Instead: & lt; Div & gt; My city is xCity and I think that xCity is the best city in the world. Everyone should live in xCity! & Lt; / Div & gt;

Use:

  & lt; Php $ xCity = 'Calgary'; ? & Gt; & Lt; Div & gt; My city & lt; Php echo $ xCity; ? & Gt; And I think & lt ;? Php echo $ xCity; ? & Gt; The best city in the world. To each person & lt; Php echo $ xCity; Should stay in ? & Gt ;! & Lt; / Div & gt;    

No comments:

Post a Comment