-3

I need the regex code for Pawn. I need a code which I can use with preg_replace, too.

Also what i use, is worse...

So, my code is.

$text = preg_replace('/([\\\\\|\'|"])/', '\\\$1', $text);

Is this right? This code would replace the in PHP documentation given characters etc. But it replaces all \ :/ \n etc., too!

Have you a Code, which only replaces the following characters? http://de3.php.net/manual/de/function.mysql-real-escape-string.php

\x00, \n, \r, \, ', " und \x1a

halfer
  • 19,824
  • 17
  • 99
  • 186
Patrick
  • 829
  • 2
  • 13
  • 34
  • 2
    You're trying to replace mysql_real_escape_string with a call to preg_replace? Bad, bad idea. – Corbin May 05 '12 at 10:38
  • The Language "PAWN" haven´t a mysql_real_escape_string or a Function like this. Because this, i must use regex for this. Couldn´t you help? :/ In PHP the Function exist, also why i should replace it ^^ its only for "pawn", Sa-MP Language etc. – Patrick May 05 '12 at 10:48
  • 1
    OK, wait, so your question is **What is the equivalent of `mysql_real_escape_string` for the [Pawn language](http://www.compuphase.com/pawn/pawn.htm)**? If so, how are you connecting with it to a database in the first place? – deceze May 05 '12 at 10:58
  • I changed the Title. Yes, this is my Question. To a Database i connect with a Plugin. But this is no matter... I need only the regex Code :/ – Patrick May 05 '12 at 11:44
  • 1
    That plugin does not offer any sort of parameter escaping? – deceze May 05 '12 at 11:48
  • _I need a regex code for Pawn_ - can you expand on that? What do you want that regex to do? It isn't clear from your question at the moment. (I've edited it as best I can, but if you can edit further, that would be helpful). – halfer May 05 '12 at 11:52
  • @deceze: i said: no matter / worse / etc.... you dont know? – Patrick May 05 '12 at 12:36
  • @halfer: The Regex should have the same Function like mysql_real_escape_string... Also it should replace \x00, \n, \r, \, ', " und \x1a. My Code replaces all \ etc. or i´ve been right??? Is My Code okay/good? – Patrick May 05 '12 at 12:37
  • 1
    Are you connecting to a MySQL database using Pawn, and needing an equivalent of `mysql_real_escape_string` in Pawn? – halfer May 05 '12 at 13:41
  • ........... I need a Regex Function.... – Patrick May 05 '12 at 14:42
  • Couple of things: firstly, people don't get your messages unless you call them by name (@halfer). Secondly, I asked you to clarify what you needed this function for, so people can give you a relevant response. Please do so `:)` – halfer May 05 '12 at 17:28
  • @halfer: okay :) i need this function for escape strings like 'Hello ' " you'. This String i would save with MySQL. And because the String is sad, i need an Escaping ^^ :/ – Patrick May 08 '12 at 18:40
  • @Charles - if you're sure `pawn` is an inappropriate tag, I won't rollback again. But this is indeed a question connected to that programming language. – halfer May 12 '12 at 00:43

2 Answers2

1

Bearing in mind I've not heard of Pawn until now, ten minutes of web searching found this and this - both of which I think answer your question. This is assuming that you are looking for a way to escape strings in the Pawn language.

As @Corbin says, it is not a good idea generally to do escaping on your own, unless your language/library doesn't offer an escape function. But this library appears to offer mysql_real_escape_string, just like PHP.

halfer
  • 19,824
  • 17
  • 99
  • 186
0

What are you creating Pawn scripts for? If it's SA-MP, you should simply use the mysql_real_escape_string function, which is provided by all released MySQL plugins.

Escaping MySQL with regex is a really bad idea, as different MySQL servers have different requirements. It'd also be slower.

Oscar Broman
  • 1,109
  • 8
  • 19