473,324 Members | 1,678 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

preg_replace question

Hi,

I want to turn the following:

<ref>Name & Name2, 1999</ref>

into

<a href="index.php?ref=Name + Name2, 1999">Name & Name2, 1999</a>

I now have to following code:

$text = preg_replace("/<ref>([^<]+)<\/ref>/m","<a
href=\"index.php?ref=\\1\">\\1</a>",$text);

The problem is that &-sign are not converted to + sign. That is really
needed because & marks the end of the variable $ref

How can I improve this function so that the replacement works like I want it
to?

- Daniel
Jul 16 '05 #1
0 2594

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: JDJones | last post by:
Just want to verify. I have a form and I want to parse any semi-colons out of the submitted info and replace with commas. Would this be the correct way to do it? $question1 = preg_replace(";",...
1
by: yawnmoth | last post by:
say i have the following script: <? $test = "aaaaa"; print '"' . preg_replace('/.*/','x',$test) . '"<br>'; $test = "\n\n\n\n\n"; print '"' . preg_replace('/.*/','x',$test) . '"'; ?> the...
7
by: Margaret MacDonald | last post by:
I've been going mad trying to figure out how to do this--it should be easy! Allow the user to enter '\_sometext\_', i.e., literal backslash, underscore, some text, literal backslash, underscore...
4
by: leegold2 | last post by:
preg_replace(","," ",$kw_str2); This does not replace commas with spaces. What am I doing wrong? Thanks, Lee G.
9
by: ihatzi | last post by:
Hey all! I am having a bit of trouble getting this to work. You all are probably familiar with the code that strips HTML tags: $PageText = preg_replace("/<.+?>/","",$WebPage); What I need...
3
by: Charles | last post by:
I'm new to this regular expression stuff. I'd like to use preg_replace to eliminate a known multi-line signature from the body of an E-mail. Say the body text is in $body, and the sig is this ...
5
by: julianmlp | last post by:
I'm fairly new to regex code, and I'm trying to find a way to replace any text after "///" (three slashes) and before a "\n" character. I've tried with: $filen = preg_replace("///./\n$", "",...
1
by: otrWalter | last post by:
I have a very specific need. Too long to get into what and why here (If you please). I have this test code... $_str = "testing that'S supposed to work!"; // Notice the CAP 'S, this is the...
10
by: deko | last post by:
I need to capture referrers to a website and populate a page with links to the referring pages. How do I use preg_replace to search for and replace all ampersands ('&') with the corresponding...
8
by: erikcw | last post by:
Hi all, I'm trying to write a regex pattern to use in preg_replace. Basically I want to put around every line (\n) in this variable. However, I need to exclude lines that already have brackets...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.