3

Updating the Question:

$li_text = $li->plaintext;
echo '<br>'.$li_text;
echo '<br>'.$li_text = preg_replace('/\:(.*?)\>/',':', $li_text);

$li getting the Value "Qualification : School & Graduation > BE / B.Tech ( Engineering ) " //by using simple html DOM parsing from other websites

The output i am getting is

Qualification : School & Graduation > BE / B.Tech ( Engineering )
Qualification : School & Graduation > BE / B.Tech ( Engineering ) 

If i assign $li_text = "Qualification : School & Graduation > BE / B.Tech ( Engineering )" then the REGEX is working fine.

3
  • 1
    Are you sure? This seems to be working on regex101. Commented Jun 3, 2013 at 12:53
  • 2
    I just tested them and they worked fine. Are you assigning the return value of preg_replace back into $str? (Had to ask; sometimes it's the simple things) Commented Jun 3, 2013 at 12:56
  • @dleiftah I think that's what's happening. Commented Jun 3, 2013 at 12:58

2 Answers 2

2

Your code is working fine. Please notice that preg_replace doesn't change the subject (i.e. $str) but returns a result.

preg_replace() returns an array if the subject parameter is an array, or a string otherwise.

If matches are found, the new subject will be returned, otherwise subject will be returned unchanged or NULL if an error occurred.

So:

preg_replace('/:(.*?)\>/',':', $str);

echo $str;

is wrong. But:

$str = preg_replace('/:(.*?)\>/',':', $str);

echo $str;

is working.

Sign up to request clarification or add additional context in comments.

Comments

1

Try this one :

preg_replace('/(?<=:)(.*?)>/', '', $str);

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.