Umair Malik Umair Malik - 7 months ago 34
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.


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;