Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Need to use regexp to change a variable.. Pls help!

Posted on 2006-10-29
3
179 Views
Last Modified: 2006-12-05
I'm using a filename in a variable, but ned to dynamically change the variable within the page. For example, if my filename is mainpage.htm, then I want the result to be mainpage_rt.htm. It won't always be an htm page, but it will always have an extension. Please help. THanks in advance for all the help.
0
Comment
Question by:bemara57
3 Comments
 
LVL 4

Accepted Solution

by:
KarlPurkhardt earned 500 total points
ID: 17829210
Hi,

Try the following regex:

$filename = 'somepage.html';
$add_string = '_r';

$filename = preg_replace('/(.*)(\.\w{2,5})/i', "$1$add_string$2", $filename);
      
echo 'Filename is now: ' . $filename;
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

790 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question