Umair Malik Umair Malik - 1 year ago 80
PHP Question

remove all text from string after given word in php

i've a query string like this:

SELECT * FROM `backplanechanneldecoder` WHERE Pair = '3' LIMIT 25,25

and i want to remove all the text which comes after LIMIT.

Note: This string is generated dynamically from another code on which I've no control that's why I've to remove part of string from my end.

Answer Source

Use str_pos to find the word LIMIT and then strip after that using substr

$string = 'SELECT * FROM `backplanechanneldecoder` WHERE  Pair = 3 LIMIT 25,25';
$limit_pos = strpos($string, 'LIMIT');
$string = substr($string, 0, $limit_pos);
echo $string;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download