/    Sign up×
Community /Pin to ProfileBookmark

preg_replace Regex Help!!

[CODE]
$info[0] = “/apple/farm/”;
$the_path = “/apple/”;
$cat_rep = preg_replace(“/^$the_path/”, “”, $info[0]);

echo $cat_rep;
[/CODE]

Im trting to get $cat_rep to contain “farm/”, instead I get this error:
Warning: Unknown modifier ‘a’ in

Please help. I see how its doing somethign with / and trying to end the regex with apple as a modifier. What should I do?

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@pyroJun 18.2003 — Seeing how a slash ( / ) is a regexp special character, you must use a backslash ( ) to escape them.

[code=php]<?PHP
$info[0] = "/apple/farm/";
$the_path = "\/apple\/";
$cat_rep = preg_replace("/^$the_path/", "", $info[0]);

echo $cat_rep;
?>[/code]
Copy linkTweet thisAlerts:
@iceafreak99authorJun 19.2003 — Thanks got it.
×

Success!

Help @iceafreak99 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 5.8,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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