I am new to php. I am trying extract a particular value from a joke file using file_get_content( text.txt, NULL,NULL, 200, 4)
but it returns the values after the 200th character. please is there a better way to do this. like instead of specifying the position which may vary i specify a word rather
Asked
Active
Viewed 56 times
0

Abhishek kumar
- 4,347
- 8
- 29
- 44

Jillnkir
- 15
- 5
-
– Jillnkir Aug 28 '17 at 11:01
-
No, just get the whole content and after that find your word in this string – Anarion Aug 28 '17 at 11:03
-
you want a particular line to be echoed? – StackUseR Aug 28 '17 at 11:05
-
ok will try that, thanks – Jillnkir Aug 28 '17 at 11:05
-
Ashish i want a value to be echoed – Jillnkir Aug 28 '17 at 11:07
-
here is the file: drops Input bandwidth utilization : 26.38% Output bandwidth utilization : 6.06% then thekkvmmvc. so i want just the two values so that i can save in my database. – Jillnkir Aug 28 '17 at 11:08
-
@Anarion That's a bad idea if big files are involved. – Denis Giffeler Aug 28 '17 at 11:12
-
ok. I believe you should try something like [this](https://stackoverflow.com/a/3686246/5588347). – StackUseR Aug 28 '17 at 11:14
1 Answers
0
Perhaps this solution might be what you are looking for?
<?php
$mystring = 'abc';
$findme = 'a';
$pos = strpos($mystring, $findme);
if ($pos === false) {
echo "Not found";
} else {
echo "The string '$findme' was found in the string '$mystring'";
echo " and exists at position $pos";
}
?>

kuylis
- 11
- 3
-
this gives the position which is not what i want. i want the value after the position – Jillnkir Aug 28 '17 at 11:29
-
Using substr('abcde', 0, 1); would get you the value at the given position. In this example it searches the string 'abcde' , starts at the first character and returns only 1 character. Is this perhaps what you're looking for? – kuylis Aug 28 '17 at 11:40