I'm just wondering how I could remove everything after a certain substring in PHP
ex:
Posted On April 6th By Some Dude
I'd like to have it so that it removes all the text including, and after, the sub string "By"
Thanks
I'm just wondering how I could remove everything after a certain substring in PHP
ex:
Posted On April 6th By Some Dude
I'd like to have it so that it removes all the text including, and after, the sub string "By"
Thanks
In plain english: Give me the part of the string starting at the beginning and ending at the position where you first encounter the deliminator.
Why...
This is likely overkill for most people's needs, but, it addresses a number of things that each individual answer above does not. Of the items it addresses, three of them were needed for my needs. With tight bracketing and dropping the comments, this could still remain readable at only 13 lines of code.
This addresses the following:
Usage:
Send original string, search char/string, "R"/"L" for start on right or left side, true/false for case sensitivity. For example, search for "here" case insensitive, in string, start right side.
Output would be "Now Here Are Some Words ". Changing the "R" to an "L" would output: "Now ".
Here's the function:
If you're using PHP 5.3+ take a look at the $before_needle flag of strstr()
You could do:
Try this.
Usage: