Jump to content

If any integer is in this spot


CitizenErased

Recommended Posts

Hi i'm trying to get out a sub string from multiple pages where i'm using a start point string that looks like this "(integer)" where "integer is different every time. Is there any way I can tell it that its just an integer there so if its "(3)" on one page and "(10)" on another page it will start from the same spot?

Link to comment
Share on other sites

Sounds like you are parsing some text and are wanting to use the "(NUMBER)" as a reference point. You will likely want to use regular expression (preg_match() I'm assuming)

 

You could either use a regular expression to extract out the content you want or, if you want to use string functions but just need to know the position, you can use a regex to find the "(NUMBER)" value and use that value in your string functions.

Link to comment
Share on other sites

Yeah it didn't sound right when i was writing it

 

 

$Start = "(3)";

 

$End = "string";

 

$StartPos = strpos($content, $Start);

 

$EndPos = strpos($content, $End);

 

$SubString = substr($content, $StartPos, $EndPos - $StartPos );

 

 

where "3" in "(3)" will be changing to a different integer from page to page

Link to comment
Share on other sites

Well, you can dynamically find the start text using a regex and use your current logic

//Find first instance of ( decimal )
preg_match("#\(\d+\)#", $content, $startText);
$Start = $startText[0];

 

Or you can replace all of that logic with a single regular expression to return all the text that you need. I can provide that as well but need to know whether you need the start and end text in your results.

 

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.