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) 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)
"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
.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
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)
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)
.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
"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.
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)
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) This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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("^$", "[");
|
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...
|
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 ;-)
|
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...
|
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...
|
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...
|
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...
|
by: yawnmoth |
last post by:
Say I have the following script:
<?
$string = 'test';
if (eregi("^+$",$string))
{
echo 'matches!';
}
else
{
|
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...
|
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,...
|
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...
|
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...
|
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...
|
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,...
|
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...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| | |