473,463 Members | 1,530 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Ereg specialists, I need your help

I would like a regular expression to do so:
Base:
<A HREF="somelink" maybesomthing="heretoo">linkface</A>
and I want:
(somelink) linkface
Is this possible ? If yes, how ?

And by the way, if anyone has a GOOD and CLEAR explanation about regular
expressions... please post it :-)

Aphrael, lost...
--
"La demande mondiale d’ordinateurs n’excédera pas cinq machines."
(Thomas Watson, Fondateur d'IBM, 1945)
Jul 17 '05 #1
9 1771
Aphrael wrote:
[snip]
And to make it more complex, if possible (but I doubt that), if somelink
== linkface, i would like to display only linkface. Possible with
ereg_replace ? or preg_replace ?

Aphrael... wishing upon a PHPstar ;-)
--
"La demande mondiale d’ordinateurs n’excédera pas cinq machines."
(Thomas Watson, Fondateur d'IBM, 1945)
Jul 17 '05 #2
"Aphrael" <ap*****@isuisse.com> wrote in message
news:41********@news.bluewin.ch...
I would like a regular expression to do so:
Base:
<A HREF="somelink" maybesomthing="heretoo">linkface</A>
and I want:
(somelink) linkface
Is this possible ? If yes, how ?


Perhaps something like this:

$string = '<A HREF="somelink" maybesomthing="heretoo">linkface</A>';

$newstring = preg_replace("/<a href=\"(.*)\".*>(.*)</a>/Uis","(\\1) \\2",
$string);

Chris Finke
Jul 17 '05 #3
.oO(Aphrael)
Aphrael wrote:
[snip]
And to make it more complex, if possible (but I doubt that), if somelink
== linkface, i would like to display only linkface. Possible with
ereg_replace ? or preg_replace ?


Sure. ;)
The magic needed in this case is the modifier 'e'.

$text = '<A HREF="somelink" maybesomthing="heretoo">linkface</A>';
$pattern = '#<a href="(.+)".*>(.+)</a>#eisU';
$replace = '"$1" == "$2" ? "$1" : "($1) $2"';
$result = preg_replace($pattern, $replace, $text);

Pattern Modifiers
http://www.php.net/manual/en/referen....modifiers.php

HTH
Micha
Jul 17 '05 #4
Michael Fesser wrote:
.oO(Aphrael)

Aphrael wrote:
[snip]
And to make it more complex, if possible (but I doubt that), if somelink
== linkface, i would like to display only linkface. Possible with
ereg_replace ? or preg_replace ?

Sure. ;)
The magic needed in this case is the modifier 'e'.

$text = '<A HREF="somelink" maybesomthing="heretoo">linkface</A>';
$pattern = '#<a href="(.+)".*>(.+)</a>#eisU';
$replace = '"$1" == "$2" ? "$1" : "($1) $2"';
$result = preg_replace($pattern, $replace, $text);

Pattern Modifiers
http://www.php.net/manual/en/referen....modifiers.php

HTH
Micha


Well, well, well. I do not understand the slightest part of all that,
but... it works, so... THANK YOU :D

Aphrael...
--
"La demande mondiale d’ordinateurs n’excédera pas cinq machines."
(Thomas Watson, Fondateur d'IBM, 1945)
Jul 17 '05 #5
Christopher Finke wrote:
"Aphrael" <ap*****@isuisse.com> wrote in message
news:41********@news.bluewin.ch...
I would like a regular expression to do so:
Base:
<A HREF="somelink" maybesomthing="heretoo">linkface</A>
and I want:
(somelink) linkface
Is this possible ? If yes, how ?

Perhaps something like this:

$string = '<A HREF="somelink" maybesomthing="heretoo">linkface</A>';

$newstring = preg_replace("/<a href=\"(.*)\".*>(.*)</a>/Uis","(\\1) \\2",
$string);

Chris Finke


Thanks, too, but it returns an error (about an a pattern or something
like that...)

Aphrael...
--
"La demande mondiale d’ordinateurs n’excédera pas cinq machines."
(Thomas Watson, Fondateur d'IBM, 1945)
Jul 17 '05 #6
.oO(Aphrael)
Christopher Finke wrote:
$newstring = preg_replace("/<a href=\"(.*)\".*>(.*)</a>/Uis","(\\1) \\2",
^
Thanks, too, but it returns an error (about an a pattern or something
like that...)


There's an unescaped slash in the pattern. In this case it becomes a
problem because slashes are also used as pattern delimiters.

Micha
Jul 17 '05 #7
"Aphrael" <ap*****@isuisse.com> wrote in message
news:41********@news.bluewin.ch...
And by the way, if anyone has a GOOD and CLEAR explanation about regular
expressions... please post it :-)


What you need is the camel book.
Jul 17 '05 #8
Chung Leong wrote:
"Aphrael" <ap*****@isuisse.com> wrote in message
news:41********@news.bluewin.ch...
And by the way, if anyone has a GOOD and CLEAR explanation about regular
expressions... please post it :-)

What you need is the camel book.


huuuuh... ok, thanks, will have a look *walks away puzzled...*

Aphrael...
--
"La demande mondiale d’ordinateurs n’excédera pas cinq machines."
(Thomas Watson, Fondateur d'IBM, 1945)
Jul 17 '05 #9
Michael Fesser wrote:
.oO(Aphrael)

Christopher Finke wrote:

$newstring = preg_replace("/<a href=\"(.*)\".*>(.*)</a>/Uis","(\\1) \\2",


^

Thanks, too, but it returns an error (about an a pattern or something
like that...)

There's an unescaped slash in the pattern. In this case it becomes a
problem because slashes are also used as pattern delimiters.

Micha


Ok, will try to correct that... :-)

Aphrael...
--
"La demande mondiale d’ordinateurs n’excédera pas cinq machines."
(Thomas Watson, Fondateur d'IBM, 1945)
Jul 17 '05 #10

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

Similar topics

1
by: Stefan Gangefors | last post by:
I'm trying to figure out what I'm doing wrong when using ereg(). This is my regexp: ereg("^]$", "]"); and that does'n work, but this does: ereg("^$", "[");
3
by: Martin Lucas-Smith | last post by:
Is there some way of using ereg to detect when certain filename extensions are supplied and to return false if so, WITHOUT using the ! operator before ereg () ? I have an API that allows as an...
3
by: Aphrael | last post by:
Hello all, last time, ereg specialists did help me, so I ask again: base pattern: some texte her result: the number alone So ? any idea ? Aphrael ;-)
3
by: Rafal Zak | last post by:
I have a little problem with ereg (eregi) in PHP - in some cases it behaves differently than I expect and I don`t know if my expectations are strange or there is any "syntax subtlety" I have...
3
by: Dynamo | last post by:
Hi, Thanks to all who replied to original posting.As a direct result of now gaining a better understanding of regular expressions, instead of trying to use other peoples scripts I am now trying to...
3
by: news | last post by:
I'm trying to make sure a form has only one or two digits in either of two fields. I looked at php.net and http://www.regular-expressions.info/reference.html and this is what I put together, but...
3
by: rachellara1979 | last post by:
Hi, new to PHP and to this group, so very sorry if this is simple or has been covered before. Basically want to check that a user and password (entered in a previous page) only has characters but...
18
by: yawnmoth | last post by:
Say I have the following script: <? $string = 'test'; if (eregi("^+$",$string)) { echo 'matches!'; } else {
3
by: wizardry | last post by:
hello - i need to convert this string to preg_match to support current version of php. i have googled and found some info but still get an error where it doesnt like my search string. if...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...
0
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,...
0
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...
0
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.