For example:
$string="<aa>xyz<bb>123<ccc>";
I want to get the substring 'xyz' from $string.Is it possible?
For example:
$string="<aa>xyz<bb>123<ccc>";
I want to get the substring 'xyz' from $string.Is it possible?
Simply you can use strip_tags to get xyz
<?php
echo strip_tags('<aa>xyz<bb>');
?>
strip_tags
is only striping tags. Use it only if this meets your requirement.
yes it is possible
$string="<aa>xyz<bb>";
echo substr($string,4,4);
you can also do this by strip_tags()
it Strip HTML and PHP tags from a string
You can also use a regex to explode the string into an array. this would give you the substring you want in $arr[0] This will work regardless what the tags are, and allow you to easily which ever substring you want.
<?php
$string="<aa>xyz<bb>123<ccc>";
$arr = preg_split("/<[^>]+>/", $string, 0, PREG_SPLIT_NO_EMPTY);
var_export($arr);
Use preg_match
with <aa>(.*?)</bb>
, it will be the first match.
With regular expressions you will also be able to get other matches in your string also ..