Selected from Linux Selected from PHP
- Ubuntu 17.10 Install google's mod pagespeed for apache - PHP-Ubuntu-Youtube-dl simple script for converting and downloading youtube video or mp3
- Ubuntu SSH tunnel via proxy - PHP while loop with every row with a different color
- Install GoAccess Apache Log Analyzer Tool on Ubuntu 17.10 - PHP use while loop in function
- SSHFS and map folder with a proxy - PHP List Files And Folders As links
- How to connect to SSH server with a proxy - PHP Extract Text From String
➥ PHP Extract Text From String
Added by sonik on 27-06-2018 and keywords: php, extract, text, between, words, string, substr, stripos [ Print Article ]
If you have a string like "here is my school" and you want to get only "is my" witch is between "here" and "school" this function is for you.
<?php
function extract_unit($string, $start, $end){
$pos = stripos($string, $start);
$str = substr($string, $pos);
$str_two = substr($str, strlen($start));
$second_pos = stripos($str_two, $end);
$str_three = substr($str_two, 0, $second_pos);
$unit = trim($str_three); // remove whitespaces
return $unit;
}

$output = "left side of string THIS IS WHAT WE EXTRACT right side of string";
$unit = extract_unit($output, 'left side of string', "right side of string");
echo $unit;

And here is the result:
THIS IS WHAT WE EXTRACT

@All rights reserved with Copyright Webleit.info 2018 by Sonik_Blast [ Site Map ] [ RSS ] [ YouTube Mp3 Downloader and converter ]