Jump to content

string to find a certain range {}


karker

Recommended Posts

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

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...";

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.