karker Posted April 23, 2011 Share Posted April 23, 2011 if i want find included a word in the a range how can i do it? example : array("problem is an obstacle, impediment, difficulty or challenge, or any situation that invites resolution; the resolution of which is recognized as a solutionquestion raised for inquiry, consideration, or solution proposition in mathematics or physics stating something to be done"); how can i find only start 20 charecter and my found word after 20 character by end example :if my word be inquiry i want find :...soluti onquestion raised for inquiryconsideration, or solution proposition... Link to comment https://forums.phpfreaks.com/topic/234531-string-to-find-a-certain-range/ Share on other sites More sharing options...
gevensen Posted April 23, 2011 Share Posted April 23, 2011 please clarify this statement how can i find only start 20 charecter and my found word after 20 character by end Link to comment https://forums.phpfreaks.com/topic/234531-string-to-find-a-certain-range/#findComment-1205303 Share on other sites More sharing options...
karker Posted April 23, 2011 Author Share Posted April 23, 2011 left-and right-to-20 characters and middle my wanted word in the range example : left 20 char // ..onquestion raised for inquiry consideration, or solution ... // right 20 chr Link to comment https://forums.phpfreaks.com/topic/234531-string-to-find-a-certain-range/#findComment-1205319 Share on other sites More sharing options...
wildteen88 Posted April 23, 2011 Share Posted April 23, 2011 There are many functions for manipulating text. The two functions you'll want to use for your problem would be strpos and substr. Have a readup on those two functions and see if you can work it out. Link to comment https://forums.phpfreaks.com/topic/234531-string-to-find-a-certain-range/#findComment-1205326 Share on other sites More sharing options...
karker Posted April 23, 2011 Author Share Posted April 23, 2011 the function use find in array my word after taking right-20 char and left 20char can anybody write php code? Link to comment https://forums.phpfreaks.com/topic/234531-string-to-find-a-certain-range/#findComment-1205335 Share on other sites More sharing options...
wildteen88 Posted April 23, 2011 Share Posted April 23, 2011 Example code $string = 'problem is an obstacle, impediment, difficulty or challenge, or any situation that invites resolution; the resolution of which is recognized as a solutionquestion raised for inquiry, consideration, or solution proposition in mathematics or physics stating something to be done'; $word = 'inquiry'; $word_pos = strpos($string, $word); // get the position of the word $startPos = $word_pos - 20; // 20 characters to the left of the word $endPos = strlen($word) + 40; // 20 characters to the right of the word $new_string = substr($string, $startPos, $endPos); echo "...$new_string..."; Link to comment https://forums.phpfreaks.com/topic/234531-string-to-find-a-certain-range/#findComment-1205338 Share on other sites More sharing options...
karker Posted April 23, 2011 Author Share Posted April 23, 2011 thank you wildtenn Link to comment https://forums.phpfreaks.com/topic/234531-string-to-find-a-certain-range/#findComment-1205349 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.