On Thu, 17 Oct 2002, Cameron Cooke wrote:

>-I have looked at these, and they make no sense to me. I tried the substr
>-function, but it all went a bit pear shaped.

Try something like this, you can deal with the linewraps ;)

Reference:
http://au.php.net/manual/en/function.strpos.php
http://au.php.net/manual/en/function.substr.php
http://au.php.net/manual/en/function.strlen.php


<?

$haystackText = "Oh yeah, this is The text before, during, and The text
after";

$firstString = "The text before";

$secondString = "The text after";

$positionFirstString = strpos($haystackText, $firstString);
print("<p>First Position = $positionFirstString</p>");

$positionSecondString = strpos($haystackText, $secondString);
print("<p>Second Position = $positionSecondString</p>");


if ( $positionFirstString < $positionSecondString ) {
  $firstLength = strlen($firstString);
  $diffBetweenStringPositions = $positionSecondString -
$positionFirstString - $firstLength;
  $resultText =
substr($haystackText,$positionFirstString+$firstLength,$diffBetweenStringPositions);
} else {
  $secondLength = strlen($secondString);
  $diffBetweenStringPositions = $positionFirstString -
$positionSecondString - $secondLength;
  $resultText =
substr($haystackText,$positionSecondString+$secondLength,$diffBetweenStringPositions);
}

print("<p>$haystackText<br>$resultText</p>");

?>



>-
>-Cameron
>-
>-
>-"Noodle Snacks" <[EMAIL PROTECTED]> wrote in message
>-[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
>->
>-> "Cameron Cooke" <[EMAIL PROTECTED]> wrote in message
>-> news:[EMAIL PROTECTED]...
>-> > Hi,
>-> >
>-> > I need a function to get a string in between two other strings. So you
>-> would
>-> > give the function the string to search and then you pass the first
>-string
>-> > and last string, and the function will return the string in between.
>-> >
>-> > Does anyone have this, or know how to do it. I tried but could not get
>-it
>-> to
>-> > work.
>->
>-> will substr() - http://au.php.net/manual/en/function.substr.php suit your
>-> needs?
>->
>-> if not check out:
>->
>-> http://au.php.net/manual/en/ref.regex.php
>->
>-> and
>->
>-> http://au.php.net/manual/en/ref.pcre.php
>->
>->
>-
>-
>-
>--- 
>-PHP General Mailing List (http://www.php.net/)
>-To unsubscribe, visit: http://www.php.net/unsub.php
>-

**************************************

John Huggins
VANet

[EMAIL PROTECTED]
http://www.va.net/

**************************************


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to