Solved

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

Posted on 2006-10-29
3
176 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
The viewer will learn how to dynamically set the form action using jQuery.
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…

743 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now