user2598136
user2598136

Reputation:

Using php match the two variables contents

I have some content like below.if i changed the below content how can i found out in php,mysql ? Im using tinymce editor.

In some of the cases it is not working why ? if im using spaces or some regular expresssion why so ?

  $var = "<p>- sdfsdfname as stated in P/O</p><p>- fsdfssupermarfsfked order number</p><p>- DSI: sdf</p><p>- sdfsf&amp; Co dsfnumber</p><p>- sfdsnumber</p><p>- Barcode no. and barcode(scanable)</p><p>- fQuantity of sales units containing each handling unit</p><p>- sdfof sales dsfs, colour/size</p><p>- sfsweight</p><p>- Net weight</p><p>- fdsdfsfunit marked 1 and up</p><p>- fsffor: (sdfsfname)</p>";

  $var1 = "<p>- sdfsdfname as stated in P/O</p><p>- fsdfssupermarfsfked order number</p><p>- DSI: sdf</p><p>- sdfsd&amp; Co dsfnumber</p><p>- sfdsnumber</p><p>- Barcode no. and barcode(scanable)</p><p>- fQuantity of sales units containing each handling unit</p><p>- sdfof sales dsfs, colour/size</p><p>- sfsweight</p><p>- Nesdfsdfst weight</p><p>- fdsdfsfunit marked 1 and up</p><p>- fsffor: (sdfsfname)</p>";

PHP

if($var == $var1){
echo "if";
}else{
echo "else";
}

Upvotes: 2

Views: 65

Answers (1)

I can assure you that if $var1 is the least bit different to $var then you will get the else section of your code. The fact that sometimes you are not points to two possible problems.

  1. $var1 does not receive the changes. This seems unlikely to be honest but it is one of the two things that could go "wrong" and have PHP see the two variables as the same.

  2. $var is also updated with the new string. This is more likely as this smells to me like a work-flow problem. The question I would be asking would be: Where is the script getting $var from? Presumably you set it before the changes are examined but after the data is returned by the user?

In debugging issues like this it helps to have the script spit out everything it has between two <pre> tags. Then you can examine all your variables and find out which ones are not as you were expecting.

<?php
  echo "<pre>\n";
  echo "\$var = \"{$var}\"\n";
  echo "\$var1 = \"{$var1}\"\n";
  print_r($some_array);
  // etc

Your if-then-else is correct so the question is what is happening with the variables.

Upvotes: 1

Related Questions