0

i have a string like below,

 [Session #1: Tues May 31st - Fri June 10th (1-5:30PM)#1 only: 1pmADV] => 2
    [Session #1: Tues May 31st - Fri June 10th (1-5:30PM)#1 only: 2pmADV] => 1
    [Session #2: Tues June 14th - Fri June 24th (9-2:00PM)#1 only: 2pmADV] => 1
    [Session #1: Tues May 31st - Fri June 10th (1-5:30PM)#1 only: 1pmN/S+] => 1
    [Session #2: Tues June 14th - Fri June 24th (9-2:00PM)#1 only: 2pmN/S+] => 1
    [Session #2: Tues June 14th - Fri June 24th (9-2:00PM)#1 only: 3:30pmN/S+] => 1

i need remove the text after the string "pm" upto first occurance of "]".

for example,

from
[Session #1: Tues May 31st - Fri June 10th (1-5:30PM)#1 only: 1pmADV] => 2
to
[Session #1: Tues May 31st - Fri June 10th (1-5:30PM)#1 only: 1pm] => 2

how can i do this?

3 Answers 3

1

If all your strings are in this kind of format, you could use basic string functions

$str = "[Session #1: Tues May 31st - Fri June 10th (1-5:30PM)#1 only: 1pmADV]";
$str = substr($str, 0, strpos($str, "pm") + 2);
$str .= "]";
Sign up to request clarification or add additional context in comments.

Comments

0
$str = "[Session #1: Tues May 31st - Fri June 10th (1-5:30PM)#1 only: 1pmADV] => 2"
echo preg_replace('/(?<=pm)\S*?(?=])/is', '', $str);

Comments

0

How about:

$str = preg_replace("/(pm)[^\]]+(\])/", "$1$2", $str);

This will remove all characters that are not ] between pm and the first occurrence of ]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.