0

this is my php code to check whether a tag named $GEcode exsits as node in _.xml file: in line 4, when I write GEcode=$GEcode, it echo 'not exsits', when the quotation marks exsit(GEcode='$GEcode'), it return "exsits". I am confused, $GEcode is already a string, why still need quotation marks? (in the form, name="GEcode"; value = "GE1319")

1.<?php
2.$courselist = simplexml_load_file("_.xml");
3.$GEcode = $_POST['GEcode'];
4.$course=$courselist->xpath("child::course[GEcode='$GEcode']");
5.if(empty($course)){
6.echo "not exsits";
7.}
8.else{
9.echo "exsit";
10.}
11.?>
xhg
  • 1,850
  • 2
  • 21
  • 35

1 Answers1

0

Consider the string that is being passed to xpath. With the quotes, it's:

child::course[GEcode='GE1319']

without quotes, it's:

child::course[GEcode=GE1319]

this is invalid xpath syntax, since the value must be quoted.

Joe
  • 6,767
  • 1
  • 16
  • 29