473,785 Members | 2,575 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

=("|\')?([^ "\']*)("|\')?.*>([^<]*)</A>'

Hello.
Well, I found this piece of code on php.net. Thats fine but where can i find
explanation for all these ("|\')?([^ "\']*)("|\')?.*>([^<]*)' syntax so that
I can construct my own rules for all kind of eregi preg and oter match
functions ?

Transform HTML links into plain-text "links" with the URL visible

function AHREF2text($str ing) {
return eregi_replace(' <A .*HREF=("|\')?([^ "\']*)("|\')?.*>([^<]*)</A>',
'[\\4] (link: \\2)', $string);
}
Jul 17 '05 #1
6 2590
And another simple question, maybe its the same answer.
whats the syntax of eregi_replace if I want to match ( remove in this
case ) few strings, not one:
eregi_replace (("stringone" && "stringtwo" ), "", $source)
Or it just requires whole eregi expression each time ?
This ofcourse doesn't work but hope you know what I mean.
Jul 17 '05 #2
lecichy wrote:
And another simple question, maybe its the same answer.
whats the syntax of eregi_replace?
You better switch to preg_ functions. They're faster and more powerful
than ereg*
if I want to match ( remove in this case ) few strings, not one:
eregi_replac e (("stringone" && "stringtwo" ), "", $source)
Try
<?php
$destin = preg_replace('/string(?:one|tw o)/i', '', $source)
?>
/string(?:one|tw o)/i -- means:

/ # start of regex
string # match "string literally"
(?: # start a group but don't grab (no need for that)
one # literal "one"
| # OR
two # literal "two"
) # end group
/i # end regex, but match without regard to case
see the preg_ function at
http://pt.php.net/manual/en/ref.pcre.php

Also try regex-coach from http://weitz.de/regex-coach/

using the PCRE_EXTENDED modifier (x) you can put the regex and
the comments in the source file

<?php
function AHREF2text($str ing) {
return preg_replace(
'@ # start of regex
<a[ ] # literal "<a " (notice the space)
[^<]* # any number of (any characters EXCEPT "<")
href= # literal "href="
("|\')? # optional double OR single quote (grabbed)
([^"\']*) # any number of (anything BUT double
## OR single quote) (grabbed)
("|\')? # optional double OR single quote (grabbed)
[^>]* # any number of (any characters EXCEPT ">") # a literal ">"

([^<]*) # any number of anything BUT "<" (grabbed)
</a> # literal "</a>"
@ix', # end regex, caseless and extended

'[\\4] (link: \\2)', $string);
}

// =============== ==============

$x = 'At <a href="http://mysite.example. com/">my site</a> there
are many <a href="http://examples.exampl e.com/">examples</a> :)';

echo $x, '<hr />', htmlentities($x ), '<hr />', AHREF2text($x);
?>
--
I have a spam filter working.
To mail me include "urkxvq" (with or without the quotes)
in the subject line, or your mail will be ruthlessly discarded.
Jul 17 '05 #3
Thank you so much Pedro!
Jul 17 '05 #4
lecichy wrote:
Thank you so much Pedro!


You're welcome lecichy.
Hope you enjoy regex's and the power they give you.

--
I have a spam filter working.
To mail me include "urkxvq" (with or without the quotes)
in the subject line, or your mail will be ruthlessly discarded.
Jul 17 '05 #5
You're welcome lecichy.
Hope you enjoy regex's and the power they give you.

--
I have a spam filter working.
To mail me include "urkxvq" (with or without the quotes)
in the subject line, or your mail will be ruthlessly discarded.


Enjoy what ?

Just kidding :P
Now I'm so powerful that even my mom is afraid to come to my room ;)
Jul 17 '05 #6
lecichy wrote:
Now I'm so powerful that even my mom is afraid to come to my room ;)


Moms have more power than all the regex gurus put together!

--
I have a spam filter working.
To mail me include "urkxvq" (with or without the quotes)
in the subject line, or your mail will be ruthlessly discarded.
Jul 17 '05 #7

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

Similar topics

43
5128
by: steve | last post by:
I am quite frustrated with php’s include, as I have spent a ton of time on it already... anyone can tell me why it was designed like this (or something I don’t get)? The path in include is relative NOT to the immediate script that is including it, but is relative to the top-level calling script. In practice, this means that you have to constantly worry and adjust paths in includes, based on the startup scripts that call these...
32
33070
by: Nuno Paquete | last post by:
Hi group. I'm using this code to see if is there any parameter for variable "menu": if($_GET == "downloads") .... But this code log errors if there is no parameter passed (this heappens at the first time the page is loaded). I tryed this code:
10
12634
by: Average_Joe | last post by:
Hello PHP people, Was wondering if PHP5 had some sort of "nested class" functionality. I'm trying to figure out how to return an object (with a private constructor) that has access to variables in another class. Something like: $obj = $factory->getObject("1234");
1
8065
by: David Furey | last post by:
Hi I have an XML documnet and a XSLT document as shown below THe XSLT document brings back a filtered docmument that has the VendorName that starts with a particular sub-string This works as expected with alphabet and number characters and the ' (single quote &apos; entity) character but does not work if a double quote character " is part of the string to filter on This returns all Vendor Names that begin with A (either case)
3
3646
by: NecroJoe | last post by:
I am using PHP to generate a little javascript for one of my pages. In short it allows a user to select a value from a list and pop it into a form field on a seperate page. This works well unless there is a " or ' in the character string. <SCRIPT language=JavaScript> function Add_Term(SearchTerm) { window.opener.document.advsearch.name_title.value += SearchTerm; window.close();
5
3463
by: Mateusz Loskot | last post by:
Hi, I'd like to ask how XML parsers should handle attributes which consists of &quot; entity as value. I know XML allows to use both: single and double quotes as attribute value terminator. That's clear. But how should parser react for such situation: I have CORDSYS element with string attribute which consists of value with many &quot; entities:
3
2712
by: Arpi Jakab | last post by:
I have a main project that depends on projects A and B. The main project's additional include directories list is: ...\ProjectA\Dist\Include ...\ProjectB\Dist\Include Each of the include directories contain a file named "cppfile1.h". In my main project I #include "cppfile1.h". I rely on the order of paths in additional include directories list to get file cppfile1.h from ProjectA and
5
3448
by: martin | last post by:
Hi, I would be extremly grateful for some help on producing an xml fragemt. The fragment that I wish to produce should look like this <Addresses> <Address>&qout;Somebody's Name&quot; &lt;me@mydomain.com&gt;</Address> </Addresses>
1
2845
by: manchin2 | last post by:
Hi, Can anybody please provide the information about "&quot" and its use, if possible please provide an example. 1)<tm:bom-expression>{Conf.getEquityConfLookupFields().getEventFieldText(&quot;AdditionalDisruption&quot;,&quot;Change in Law&quot;)}</tm:bom-expression> 2)07:41:08 Default ( call ( . ( call ( . Conf getEquityConfLookupFields ) ) getEventFieldText ) ( , AdditionalDisruption Change inLaw ) ) value=Not applicable Can you please...
4
3896
by: fran7 | last post by:
Hi, from help in the javascript forum I found the error in some code but need help. This bit of code works perfectly, trouble is I am writing it to a javascript function so the height needs to be in &quot;&quot; instead of "" otherwise I get an error message. Can anyone suggest how to write it so that it writes &quot; instead of "". I have tried all combinations of adding &quot; to the code but as soon as I think I am there I get throw out again. if...
0
9480
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10325
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
10148
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...
1
10091
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9950
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
8972
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
7499
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...
2
3646
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2879
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.