Alexxxx Alexxxx - 1 year ago 155
PHP Question

How to remove part of string in php?

I have this string


I want to remove everything after '>' including '>'

I tried this

$category = substr($categoryGet,0,strrpos($categoryGet.">",">"));

No result so far

Answer Source

You can use preg_replace

$category = preg_replace('/>[^>]*$/m', '', $category);

The regular expression matches > followed by any non-> characters until the end of the line. The m modifier makes $ match the end of each line in the string.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download