473,394 Members | 1,738 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,394 software developers and data experts.

"Ereg_replace" regular expression woes

Hi.

I'm trying to use ereg_replace to turn some text based hyperlinks into WML
code. WML is similar to HTML, except for mobile phones and very strict. That
means that there's some characters you can't use in certain places. Here's
my current code.

$string = eregi_replace(" ((http|https|rtsp)://[^[:space:]]+[[:alnum:]/])","
<a href=\"\\1\">\\1</a>", $string);

That almost works well enough, but I need to add some more conditions. The
output CANNOT contain the words:

& q u o t ;
& g t ;
& l t ;

(ignore the spaces). If it does find those things it should break off, just
like when it finds a space. So far attempts to add this in have been
completely fruitless. Help would be very much appreciated!

Rob
Jul 17 '05 #1
1 1475
Rob Pridham wrote:
$string = eregi_replace(" ((http|https|rtsp)://[^[:space:]]+[[:alnum:]/])","
<a href=\"\\1\">\\1</a>", $string);

That almost works well enough, but I need to add some more conditions. The
output CANNOT contain the words:

& q u o t ;
& g t ;
& l t ;

(ignore the spaces). If it does find those things it should break off, just
like when it finds a space. So far attempts to add this in have been
completely fruitless. Help would be very much appreciated!


I think your best bet is to search for the forbidden content directly
and not within a regular expression.

Do the eregi_replace and then test for the forbidden content, maybe with
something like:

<?php
// ... including the eregi_replace()
if (strpos($string, '&quot;') !== false) die('broken URL');
if (preg_match('/&[gl]t;/', $string)) die('broken URL');
// ...
?>
--
--= my mail box only accepts =--
--= Content-Type: text/plain =--
--= Size below 10001 bytes =--
Jul 17 '05 #2

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

Similar topics

23
by: ian justice | last post by:
Before i post actual code, as i need a speedyish reply. Can i first ask if anyone knows off the top of their head, if there is a likely obvious cause to the following problem. For the moment i've...
0
by: |-|erc | last post by:
<?php // Get the names and values for vars sent by index.lib.php3 if (isset($HTTP_GET_VARS)) { while(list($name,$value) = each($HTTP_GET_VARS)) { $$name = $value; }; };
1
by: denisb | last post by:
hello all, for a search engine, I'm looking for a regexp than can do the job it is just (!) a 's' problem (frequent in french) : I have a field 'thesaurus' in a table MySQL (3.23.56) ; I...
10
by: Terry Olson | last post by:
I want to search a textbox and replace any instances of the dollar sign character. But when I do that it thinks it won't work because it think's I'm looking to replace something at the end of the...
4
by: Friday | last post by:
Being an Old L.A.M.P guy, I beg you to please excuse my ignorance of dot.net (and all things Windows, for that matter). As part of an experiment (to learn enough ASP/VB.net to port a series of ...
2
by: encepif | last post by:
I think this is the right command., could someone please show me how to replace instances of a quote like this " with its html version - &quot;. I am mixed up with the escaping, etc. Thank you :-) ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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...

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.