how to match a string containing special characters with sub

General discussions related to php

Moderators: macek, egami, gesf

vikaskumar615
New php-forum User
New php-forum User
Posts: 1
Joined: Sun Jul 07, 2013 10:22 pm

how to match a string containing special characters with sub

Postby vikaskumar615 » Sun Jul 07, 2013 10:26 pm

how to match a string containing special characters with substring? this is the code:-
$team="Sri";
$c="West-Indies-vs-Sri-Lanka-5th-Match";
$d=preg_match($c,$team,$matches);

i have tried preg_quote but that does not work.

$c=preg_quote('#'."West-Indies-vs-Sri-Lanka-5th-Match".'#','-');

plz help.

johnj
php-forum Super User
php-forum Super User
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm

Re: how to match a string containing special characters with

Postby johnj » Mon Jul 08, 2013 2:58 am

if you want to match a single time, then use stripos(). Otherwise use preg_match_all()

johnj
php-forum Super User
php-forum Super User
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm

Re: how to match a string containing special characters with

Postby johnj » Mon Jul 08, 2013 3:02 am

Try this:

$team="/Sri/";
$c="West-Indies-vs-Sri-Lanka-5th-Match";
$d=preg_match($c,$team,$matches);

http://phillipnb.wordpress.com/2011/03/ ... ns-part-1/


Return to “PHP General”

Who is online

Users browsing this forum: No registered users and 0 guests

cron