473,396 Members | 2,129 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,396 software developers and data experts.

dot-space in href regexp needed

Hello
Here's the thing
I have a database edited by some company workers editing descriptions of
books in the sotre , unfortunately these workers do not have the habit of
inserting a space character after word-ending dot, this is why i use the
function:

function getCorrect($txt) {
$txt=str_replace(",",", ",$txt);
$txt=str_replace(".",". ",$txt);
$txt=str_replace(". ,",".,",$txt);
$txt=str_replace(". . . ","... ",$txt);
$txt=str_replace(":",": ",$txt);
$txt=str_replace(";","; ",$txt);
$txt=str_replace("]","] ",$txt);
$txt=str_replace("... ]","...] ",$txt);
$txt=str_replace(")",") ",$txt);
$txt=str_replace("... )","...) ",$txt);
$txt=str_replace(" "," ",$txt);
$txt=str_replace("„ ","„",$txt);
$txt=str_replace(". )",".) ",$txt);
return $txt;
}

this basically closes the problem, but what bothers me recently is that i
need to indert a href link into this description and i get a result like
www. blah. com/index. php

is there anone who could help me out writing a regexp converting a ". " into
"." if it is inside href="xxx"
i'm not very familiar with regexp's so i would really appreciate your help

TIA
Patrol
Jul 17 '05 #1
2 2545
.oO(Patryk Konieczka)
I have a database edited by some company workers editing descriptions of
books in the sotre , unfortunately these workers do not have the habit of
inserting a space character after word-ending dot, this is why i use the
function:
Some things about this function:
function getCorrect($txt) {
$txt=str_replace(",",", ",$txt);
$txt=str_replace(".",". ",$txt);
[...]
1) It's not the best way to call functions like str_replace() again and
again, there are ways to do such replacements with a single function
call (with strtr() for example).

2) You don't need double quotes there, single quotes around the strings
are enough. This saves some CPU cycles and some work for the parser,
because there are no embedded variables it has to look for.

3) Especially in such constructs like above it makes sense to separate
the function arguments not only by comma, but by a comma and a space,
which makes the code a bit more readable.
this basically closes the problem, but what bothers me recently is that i
need to indert a href link into this description and i get a result like
www. blah. com/index. php

is there anone who could help me out writing a regexp converting a ". " into
"." if it is inside href="xxx"
i'm not very familiar with regexp's so i would really appreciate your help


OK, I've done the entire thing with a regular expression - and it looks
really terrible ... ;)

It should do nearly the same like your original function. There are some
little modifications on when a space will be added to punctuation chars
and when not. I tried to avoid single tests for each special char and
used a more general approach. You have to test if it works for you this
way.
Additionally it replaces chars only outside of HTML tags. Such "negative
matching" is not possible with regular expressions (except for negative
character classes and assertions, but this won't work here) and has to
be done with PHP. Thankfully PHP knows the modifier e, so it's possible
to "smuggle" some executable code into the pattern matching process.

The function:

function getCorrect($txt) {
$search = '/((<[^>]*)|((?<!&#\d{4});|[.,:)\]])(?![\s.,:;)\]]))/e';
$replace = '"$1" == "$2" ? "$1" : "$1 "';
return preg_replace($search, $replace, $txt);
}

A test string:

$test =
'Foo,bar:This here...is (just)a simple
<a href="http://www.example.com">Test</a>.„Maybe it
works (as expected),maybe not...';

getCorrect($test) returns:

'Foo, bar: This here... is (just) a simple
<a href="http://www.example.com">Test</a>. „Maybe it
works (as expected), maybe not... '

HTH
Micha
Jul 17 '05 #2
Thank you very very much
HTH


It sure did help, I really appreciate it
Take care
Patrol
Jul 17 '05 #3

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

Similar topics

17
by: HankC | last post by:
Hello: Sorry if I'm asking obvious questions but I'm still a little on the fringe of the python scene... I'm slowly migrating from Delphi/Kylix to Python/Wx to facilitate cross-platform...
3
by: robert | last post by:
Hi everyone, I have a little question. In Visual studio 6 the MFC is based under API WIN 32. In dot net, the MFC of dot net, are based on API of dot net or on API WIN 32? And my last...
44
by: Darryl Kerkeslager | last post by:
I once did all my control references with the bang (!) operator. All my controls were referenced as Me!txtInput, etc. I have now discovered that doing this loses much more than Intellisense. ...
3
by: Christopher M. Lusardi | last post by:
Hello, Can you tell me is it my imagination, or should I not stick a "volatile" definition into a dot h file? My problem is if I put my declaration in main.c before main () my code works....
3
by: marcel | last post by:
Recently we have been looking at converting our systems over to Dot net. What has been of concern is the excessive amount of resources that a C# SQL web page requires as apposed the ASP/SQL We...
7
by: aaj | last post by:
Hi all Would anyone be able to offer any unbiased thoughts or advice on reasons to switch to .Net. I have read some of the literature and read other stuff on google, but a so much of it seems to...
7
by: David Laub | last post by:
I've also posted this issue to a Sun/java formum, but since it appears to be an integration issue, this may be the better place to posr: I have written a dot net/c# Web Services doesn't fully...
7
by: Stu | last post by:
Hi, I have a web service which returns a record set and works well integrated with an asp dot net page. However if I decided to develop a unix app will i be able to read the dataset as it is...
6
by: jawolter | last post by:
I have a list of links that are sometimes too long to display on a given screen. I want to trim the ends of them if they are too long, and show dot dot dot. If the browser is widened, though, and...
0
by: =?Utf-8?B?SmFtZXMgVA==?= | last post by:
Hi, Not sure if I have the correct group, but thought I would try anyway :) I have just had a programming company produce a piece of software that requires dot net 1.1. During the...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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
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,...
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...
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
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...

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.