473,659 Members | 2,624 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

preg_replace backreferencing problem

I've been puzzling over something for ages and now give up:

Does anyone see any problem with any of the following:

$line = preg_replace('/\[#([A-Fa-z0-9]{1,6})\]/i', "<font color='#
${1}'>", $line);

$line = preg_replace('/\[(#(([A-Fa-f0-9]){3}(([A-Fa-f0-9]){3})?))\]/
i', "<font color='#${1}'>" , $line);

I tried both ; both don't work.

This snippet should convert something like [#FF0000] (hex colours)
into an HTML font tag. I believe the reg.exp IS matching (since I do
get a <fonttag), but the backreferencing is not working since the
font tag would contain an empty hex code.

I've tried using \\1 for the backreferencing , or even \\0 just to test
- but even that doesn't work.

Is it possible that backreferencing can just be turned off?!?

- Terence

May 24 '07 #1
2 1532
On May 25, 6:24 am, Terence <terence.par... @gmail.comwrote :
I've been puzzling over something for ages and now give up:

Does anyone see any problem with any of the following:

$line = preg_replace('/\[#([A-Fa-z0-9]{1,6})\]/i', "<font color='#
${1}'>", $line);
try:
$line = preg_replace('/\[#([A-Fa-z0-9]{1,6})\]/i', "<font color='#
$1'>", $line);

May 25 '07 #2
On 25.05.2007 01:24 Terence wrote:
I've been puzzling over something for ages and now give up:

Does anyone see any problem with any of the following:

$line = preg_replace('/\[#([A-Fa-z0-9]{1,6})\]/i', "<font color='#
${1}'>", $line);

$line = preg_replace('/\[(#(([A-Fa-f0-9]){3}(([A-Fa-f0-9]){3})?))\]/
i', "<font color='#${1}'>" , $line);

I tried both ; both don't work.

This snippet should convert something like [#FF0000] (hex colours)
into an HTML font tag. I believe the reg.exp IS matching (since I do
get a <fonttag), but the backreferencing is not working since the
font tag would contain an empty hex code.

I've tried using \\1 for the backreferencing , or even \\0 just to test
- but even that doesn't work.

Is it possible that backreferencing can just be turned off?!?

- Terence
$line = preg_replace('/\[(#[A-F0-9]+)\]/i', "<font color='$1'>", $line);

the correct syntax is $1 not ${1} or similar.

--
gosha bine

extended php parser ~ http://code.google.com/p/pihipi
blok ~ http://www.tagarga.com/blok
May 25 '07 #3

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

Similar topics

3
4317
by: TXSherry | last post by:
Hi, I cannot seem to wrap my brain around preg_replace. Though I've read the help file backwords and forwards. :/ Hoping someone can give me a solution here. Problem: Given string 'str' which may contain new lines and will contain html code, IN this string any "words" that begin with an underscore I want to replace with a given word. A word here being a group of chars preceded by a space or null (start of line) and closed by a...
1
2238
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 output i would expect is as follows:
7
4994
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 and, after submitting via POST to a preg_replace filter, get back '_sometext_' (i.e., the same thing with the literal backslashes stripped)
1
1776
by: rybasso | last post by:
Hello, Does anyone has an idea why preg_replace() cause 'This page contains no data' in FF and 'This page could not be found' in IE. I spend a lot of time searching any ideas on newsgroups but found nothing corresponding. Here is the code:
1
2507
by: Dave | last post by:
Hi, This is an interesting problem I'm faced with. I have been trying all sorts of functions to fix it and my last resort is to ask you guys and girls. I have an array: $arr(=>"aaa",=>"bbb",=>"ccc",=>"etc"); $html='<html>....<a href="page.php?var=3">3</a><a href="page.php?var=345">345</a...<a href="page.php?var=n">n</a>...</html>';
7
2032
by: monomaniac21 | last post by:
hi all using preg_replace how can i replace the letter i in a string with nothing (delete it) when it is the last letter or it is followed by an i? i have products that are listed in a db with i or ii as in 320ii and i want to strip out the i's at the end when displaying the product name
1
1296
by: K. | last post by:
Hello! I would like to use preg_replace function to leave in the result variable only: 1) letters from A to Z including Polish letters like ±¶¼³óñê including Polish upper letters like ¡¦¬£ÓÑÊ 2) letters ()-_=+!@#$%^&*`~',/\|. I have for example such varaible
3
1015
by: Silvertype | last post by:
Hi guys, I have these html tags: <input type="text" id="txtName" name="txtName" /> <textarea id="taHello" name="taHello">hello world</textarea> which I want to replace with the following tags:
5
2174
by: helraizer1 | last post by:
Hey folks and folksesses, I have written some code to get emoticons onto my image based shoutbox but there is quite a large bug, as there is with any code in the early stages, and I need your help to narrow it down for me. The idea is that the script pulls data from the database - username, colour, font and shout to print ' shout' onto the image. This part of the code all works perfectly. Then it looks through each line at a time to see if...
0
8851
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8751
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8630
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7360
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6181
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5650
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4176
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4342
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1982
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.