将变量与字符串进行比较不起作用

时间:2019-07-26 09:30:27

标签: php

因此,我试图将一个变量与一个字符串进行比较,甚至回显该变量以确保它与我要比较的字符串相同,但是它将不起作用。

    $output = str_replace(',', '<br />', $row['order_summary']);
    $firstBreak = strpos($output, '<br />');
    $firstWord = explode(' ',trim($output))[0];         
    if ($firstWord == 'first' || $firstWord == 'second') {
        $output = str_replace(',', '<br />', $row['order_summary']);
        $firstBreak = strpos($output, '<br />');
        if($firstBreak === false) {
            $output = "<b>$output</b>";
        } 
        else 
        {
            $output = '<b>' . substr($output, 0, $firstBreak) . '</b>' . substr($output, $firstBreak);
        }
        echo $output;
    }
    else
    {
        $output = str_replace('.', '<br /><br>', $row['order_summary']);
        $firstBreak = strpos($output, '<br />');
        $output = '<b>' . substr($output, 0, $firstBreak) . '</b>' . substr($output, $firstBreak);
        echo $output;
    }

$firstWord当我回显它时,结果是给我first,因此它显然应该通过if语句,而不是else语句。

1 个答案:

答案 0 :(得分:0)

// Wire Slave Receiver
// by devyte
// based on the example by Nicholas Zambetti <http://www.zambetti.com>

// Demonstrates use of the Wire library
// Receives data as an I2C/TWI slave device
// Refer to the "Wire Master Writer" example for use with this

// This example code is in the public domain.


#include <Wire.h>

#define SDA_PIN 12
#define SCL_PIN 13

const int16_t I2C_SLAVE = 0x12;

void setup() {
  Serial.begin(115200);           // start serial for output

  Wire.begin(SDA_PIN, SCL_PIN, I2C_SLAVE); // new syntax: join i2c bus (address required for slave)
  Wire.onReceive(receiveEvent); // register event
}

void loop() {
  delay(1000);
  Serial.println("Loop");
}

// function that executes whenever data is received from master
// this function is registered as an event, see setup()
void receiveEvent(size_t howMany) {

  (void) howMany;
  while (1 < Wire.available()) { // loop through all but the last
    char c = Wire.read(); // receive byte as a character
    Serial.print(c);         // print the character
  }
  int x = Wire.read();    // receive byte as an integer
  Serial.println(x);         // print the integer
}