6 Replies - 1319 Views - Last Post: 25 September 2012 - 08:00 AM Rate Topic: -----

#1 dogman73  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 17-September 12

Special Characters in Preg_Match

Posted 24 September 2012 - 06:40 PM

$renew = mysql_query("SELECT product FROM table WHERE productcode = '$sku'")or die(mysql_error());
$row1 = mysql_fetch_array($renew);
$update = $row1[0];
if (preg_match("/$mpn/i", $update)) { $doit = "N";
} else { $doit = "";
}


The problem I'm having is that sometimes $mpn is indeed contained in $update but special characters will cause it not to match. Any ideas?

This post has been edited by Dormilich: 24 September 2012 - 10:37 PM
Reason for edit:: please use [code] [/code] tags when posting code


Is This A Good Question/Topic? 0
  • +

Replies To: Special Characters in Preg_Match

#2 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3555
  • View blog
  • Posts: 10,335
  • Joined: 08-June 10

Re: Special Characters in Preg_Match

Posted 24 September 2012 - 10:39 PM

View Postdogman73, on 25 September 2012 - 03:40 AM, said:

The problem I'm having is that sometimes $mpn is indeed contained in $update but special characters will cause it not to match. Any ideas?

I donít see any relation between the two variables. there shouldnít be anything working.
Was This Post Helpful? 0
  • +
  • -

#3 dogman73  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 17-September 12

Re: Special Characters in Preg_Match

Posted 25 September 2012 - 12:07 AM

$mpn comes from a csv feed it is compared to the stored product title which is stored in MySQL db. Works 90% of the time but if $mpn contains special characters, particularly / and others it returns a no match when indeed $mpn matches within string var $update.
Was This Post Helpful? 0
  • +
  • -

#4 dogman73  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 17-September 12

Re: Special Characters in Preg_Match

Posted 25 September 2012 - 12:15 AM

Yes
Was This Post Helpful? 0
  • +
  • -

#5 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3555
  • View blog
  • Posts: 10,335
  • Joined: 08-June 10

Re: Special Characters in Preg_Match

Posted 25 September 2012 - 12:54 AM

View Postdogman73, on 25 September 2012 - 09:07 AM, said:

particularly / and others it returns a no match when indeed $mpn matches within string var $update.

well, obviously. a / prematurely closes your regular expression.

use a RegExp delimiter you donít have in that variable.
Was This Post Helpful? 1
  • +
  • -

#6 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3719
  • View blog
  • Posts: 5,991
  • Joined: 08-June 10

Re: Special Characters in Preg_Match

Posted 25 September 2012 - 06:49 AM

View Postdogman73, on 25 September 2012 - 07:07 AM, said:

$mpn comes from a csv feed it is compared to the stored product title which is stored in MySQL db.

You don't really have to do the comparison in PHP. MySQL can also do that. It has a LIKE operator for simple string comparisons, and a REGEXP operator for regular expression tests.
Was This Post Helpful? 0
  • +
  • -

#7 dogman73  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 17-September 12

Re: Special Characters in Preg_Match

Posted 25 September 2012 - 08:00 AM

View PostDormilich, on 25 September 2012 - 12:54 AM, said:

View Postdogman73, on 25 September 2012 - 09:07 AM, said:

particularly / and others it returns a no match when indeed $mpn matches within string var $update.

well, obviously. a / prematurely closes your regular expression.

use a RegExp delimiter you donít have in that variable.


Well of course it would be that easy. Thanks!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1