Hi i have the string like below,
$aa = "Ability: N/S,Session: Session #2: Tues June 14th - Fri June 24th (9-2:00PM),Time: 10:30am,cname: karthi";
$aa = "Ability: N/S,Session: Session #1: Tues May 31st - Fri June 10th (1-5:30PM),Time: #1 only: 1:30pm,cname: ravi";
$aa = "Ability: N/S,Session: Session #1: Tues May 31st - Fri June 10th (1-5:30PM),Time: #1 only: 1am,cname: mathi";
i need to write single regex for removing the particular string from “,cname:” upto last.
i need output like,
$aa = "Ability: N/S,Session: Session #2: Tues June 14th - Fri June 24th (9-2:00PM),Time: 10:30am";
$aa = "Ability: N/S,Session: Session #1: Tues May 31st - Fri June 10th (1-5:30PM),Time: #1 only: 1:30pm";
$aa = "Ability: N/S,Session: Session #1: Tues May 31st - Fri June 10th (1-5:30PM),Time: #1 only: 1am";
how can i do this in regex?
You don’t need regex for this. You can use strpos() to find the index of ‘,cname:’ and then substr() up to that index.
but if you, for whatever reason, insist on using regex for this, you’ll want to use preg_replace():
and if you don’t want to modify the string, you may want to use preg_match():