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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.