Jump to content

[SOLVED] Returning Portion of String


-entropyman

Recommended Posts

Hello,

 

I am working on returning a portion of a string between two key words. However, I have not had much luck lol.

 

So far I have:

 

<?php
$filename = ("http://xxxxxxxxxxxxx/xzcz.txt");
        $filestring = file_get_contents($filename);
$domain = strstr($filestring, 'FirstWord');
  	$new = stristr($domain, 'LastWord', true); 
echo $new;
?>

 

Can anyone help?  :)

 

???

Link to comment
https://forums.phpfreaks.com/topic/115432-solved-returning-portion-of-string/
Share on other sites

I managed to do it... A different way, not sure if its the best but eh:

 

$firstWord = "Hello";
$lastWord = "people";

$str = "Hello there, my golly there is a lot of people here!";

$str = substr($str, strpos($str,$firstWord)+strlen($firstWord),strpos($str,$lastWord)-strlen($lastWord));
echo $str;

 

strstr() wasn't working for me... So I did it like that. :)

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.