0

I have an output stream that is saved in a string called $output1, this is displayed to the user. now if I have another stream called $output2 that is identical to $output1 plus a few lines, how can I output only the part of $output 2 that is not in $output1.

For example:

$output1="this cat is";  
$output2="this cat is mine";  

I want to output:

this cat is mine

RSK
  • 17,210
  • 13
  • 54
  • 74
user1371011
  • 193
  • 3
  • 12

2 Answers2

1

There are two ways to do that -

1) <?php echo $output2; ?> - you will output This cat is mine.

2) <?php echo $output1.str_replace($output1, "", $output2); ?>

I suggest that you use first example.

Anyway, please describe more what you would like to achieve.

Currently you are specifying two variables which are almost same. You can just specify one variable, which you will use.

It's something similar to this -

You have two papers, on one you have written "This cat is" and on other you have written "This cat is mine". You will cut "This cat is" from second paper and leave only "mine". So you take a glue and stick together the first paper with "mine". = You lose time and make it complicated.

If you want to get only "mine", then use - str_replace($output1, "", $output2);

y2ok
  • 660
  • 5
  • 18
  • I'm streaming this output. I have an output generated on every time I check a file for contents. I need a way on each check to output only the part of the output that has not already been outputted to the screen – user1371011 Jul 25 '12 at 08:15
0
$output1="this cat is";  
$output2="this cat is mine";
$min=(strlen($output1)<strlen($output2)) ? $output1 : $output2 ;
$max=(strlen($output1)>strlen($output2)) ? $output1 : $output2 ;
$pos= strpos($max,$min);
//if you want "this cat is mine", maxima string
if($pos!==FALSE) echo $max;
//if you want " mine", part of the string only in the maxima one.
if($pos !==FALSE) echo substr($max,strlen($min));

EDIT:

//if you want "this cat is" from shortest string and " mine" from the other one.
if($pos !==FALSE) echo $min.substr($max,strlen($min));
Romain
  • 6,322
  • 3
  • 35
  • 40