Hi, I have been working on a simple command line program that will simply store my data in the code variable then submit that data to another program. Although I have the thory right, I don't understand why the middle double quote ( " ) seems to escape the quotes that surround the variable when it is used on the next line (variable: var).

So when I use the below code, I get the error "`[h]ref\` is not recognized as an internal or external command, operable program or batch file.". I don't understand why the quotation mark is escaping the string when it has been escaped twice and yes I have tried escaping it three times and just with the single slash. Can anybody see what is wrong with my script as I rarly use c++.

#include <cstdio>
#include <cstdlib>
#include <iostream>

using namespace std;

int main()
{
    string code = "var_dump(preg_split('/(href\\=\\'|href\\=\\\"|[h]ref\\=)/is','adslkfajal;sdfjhref=test.com/test.htm'));";
    std::string var = "C:\\z_php-gtk\\test4\\php-gtk2\\php -r \" "+code+" \"";
    cout << code << endl;
    system (var.c_str());
    system("PAUSE");
    return EXIT_SUCCESS;
}

For the sake of simplicity and less headaches I would create a parsing program.

The program will read a text file where you type line you want in there without worrying about escape sequences.

Then the program read this line and creates another string already formatted...

string quote = "\"";
string b_slash = "\\";

cout << quote + " " + b_slash;

Next try dumping the var into a .bat file and running that.

I've noticed problems when trying to run a c++ program with params.

And lastly, is that php regex legit?

And lastly, is that php regex legit?

Yes it is php regex as the c++ command prompt is communicating with the php-gtk application. Anyways, I tried the code ya supplied and it returned " \ Also I just tried putting the expected output into a batch file and the program blew up. That is it wouldn't work. I discovered that as soon as I removed the the middle double quotation mark then it worked. But I need to be able to use both types of quotations in my code though. So this isn't so much a c++ error but a dos type command line error.

Somehow I need to force php to accept the double quotes which I am working on so if I bump into more c++ errors in relation to this code then I shall post here.

This article has been dead for over six months. Start a new discussion instead.