/    Sign up×
Community /Pin to ProfileBookmark

preg_replace problem easy to regex person

I have a preg_replace problem. I am trying to get this statement to replace all instances of “St. Patrick’s Day” to a link to my patties day page!

[code=php]$details = preg_replace(‘/w(St. Patrick’s Day?)w/i’, “<a href=”erie-bars-directory/st_patrick’s_day_erie.php”>$1</a>”, $details); [/code]

is this right because it don’t do anything?

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@NogDogFeb 21.2006 — See if this works better for you:
[code=php]
$details = preg_replace('/b(St. Patrick's Day)b/i',
"<a href="erie-bars-directory/st_patrick's_day_erie.php">$1</a>",
$details);
[/code]
Copy linkTweet thisAlerts:
@ShrineDesignsFeb 21.2006 — [code=php]$details = preg_replace("/(st.[rn ]+patrick's[rn ]+day)/i", "<a href="erie-bars-directory/st_patrick's_day_erie.php">\$1</a>", $details);[/code]
Copy linkTweet thisAlerts:
@Markbad311authorFeb 21.2006 — I have to replacement going on for my $details Variable. one makes band or bands event or events and Erie bold... The other is your example. The [B]St. Patrick's Day[/B] preg_replace doesn't work yet I tried both examples. The other preg_replace is formatting some URLs too. With Strong tags right in a URL! lol machine's have no mercy ? any ways maybe adding white space or telling no double quotes can be in front of it or something?


[code=php]$details = preg_replace('/w(erie|bands?|events?)w/i', "<strong>$1</strong>",
$details);


$details = preg_replace('/b(St. Patrick's Day)b/i',
"<a href="erie-bars-directory/st_patrick's_day_erie.php">$1</a>",
$details); [/code]




in this enviorment:
[code=php]<?php
$page_title = "Erie Scene Home Page";
require("listingsfunc.php");
if ($_GET['id'] != "") {
dbconnect();
sidemenu($connection);
showsingle($connection);
} if ($_GET['show_all_erie_pa_bars']) {
dbconnect();
showall($connection);
} else if (!$_GET['id']) {
dbconnect();
eventreg($connection);
sidemenu($connection);
}

pagecount($page_title);
$details = preg_replace('/w(erie|bands?|events?)w/i', "<strong>$1</strong>", $details);
$details = preg_replace('/b(St. Patrick's Day)b/i',
"<a href="erie-bars-directory/st_patrick's_day_erie.php">$1</a>",
$details);

mysql_close($connection);
?> [/code]





check this little mishap, in a URL I need to be able to stop this from happening. with the <strong> tag preg_replace

[code=html]
<a href="%3Cstrong%3Eerie%3C/strong%3E-%3Cstrong%3Ebars%3C/strong%3E-directory/st_patrick%27s_day_erie.php">
</a>
<!-- Suppose to be-->
<!-- <a href="erie-bars-directory/st_patrick's_day_erie.php">-->
[/code]


Any ideas? I have been reading about regular expressions but haven't got any to work. lol
Copy linkTweet thisAlerts:
@NogDogFeb 21.2006 — Use b for word [b]b[/b]oundary, not w (which is any "[b]w[/b]ord character".
Copy linkTweet thisAlerts:
@Markbad311authorFeb 24.2006 — I still get this:
[CODE]http://www.eriescene.com/%3Cstrong%3Eerie%3C/strong%3E-pa-%3Cstrong%3Eevents%3C/strong%3E/%3Cstrong%3Eerie%3C/strong%3E-%3Cstrong%3Eband%3C/strong%3E-spooner-placebus.php[/CODE]

When I use this replace

[code=php]
$details = preg_replace('/b(erie|bands?|events?)b/i', "<strong>$1</strong>", $details);
$details = preg_replace('/b(St. Patrick's Day)b/i',
"<a href="erie-bars-directory/st_patrick's_day_erie.php">$1</a>",
$details);
[/code]


The "St. Patrick's Day" preg_replace still does not work either.
×

Success!

Help @Markbad311 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.30,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...