I want to do this
$name = "hello word XYZabcdefghijklmnopqrstuvwxyz bluesky";
Output should look like: "abcdefghijk"
Which are 11 characters.
Please note: XYZ is the prefix
I want to do this
$name = "hello word XYZabcdefghijklmnopqrstuvwxyz bluesky";
Output should look like: "abcdefghijk"
Which are 11 characters.
Please note: XYZ is the prefix
The method substr()
is what you're looking for:
string substr ( string $string , int $start [, int $length ] )
Returns the portion of string specified by the start and length parameters.
First you find the position of your $prefix in the $name:
strpos($name, $prefix)
Then you need to add the length of your prefix to move to the correct position, and pass the number of characters, which you want to get in the result (11 in your case):
$name = "hello word XYZabcdefghijklmnopqrstuvwxyz bluesky";
$prefix = "XYZ";
$output = substr($name, strpos($name, $prefix) + strlen($prefix), 11);
echo $output;
Try this
<?php
$name = "hello word XYZabcdefghijklmnopqrstuvwxyz bluesky";
$out = substr(substr($name, strpos($name, 'XYZ'), 14), 3);
echo $out;