|
Posted by Khs on 10/02/48 11:07
Hi, I'm trying to extract a string using 'ereg()' but it doesn't seem
to find some strings. I am using php version 4.3.10 in cli mode.
Here is an example of the input:
#include FT_FREETYPE_H
#include <stdio.h>
#include "freetype/freetype.h"
Here is a snip of my code:
$line = fgets($fp);
$line = trim($line);
$regexp = '^#include(:? | "| <)([^< >"]+)[> "]';
//$regexp = '^#include( <| "| )[^< >"]+[> "]'; //Same result as above
//$regexp = '^#include [< "]([^>" ]+)[> "]'; //Similar to above result
ereg($regexp, $line, $inclistings);
var_dump($inclistings);
Here is the output I am getting:
#include FT_FREETYPE_H
#include <stdio.h>
array(3) {
[0]=>
string(18) "#include <stdio.h>"
[1]=>
string(2) " <"
[2]=>
string(7) "stdio.h"
}
#include "freetype/freetype.h"
array(3) {
[0]=>
string(30) "#include "freetype/freetype.h""
[1]=>
string(2) " ""
[2]=>
string(19) "freetype/freetype.h"
}
Here is the output I want:
#include FT_FREETYPE_H
array(3) {
[0]=>
string(?) "#include FT_FREETYPE_H"
[1]=>
string(?) "FT_FREETYPE_H"
}
#include <stdio.h>
array(3) {
[0]=>
string(18) "#include <stdio.h>"
[1]=>
string(7) "stdio.h"
}
#include "freetype/freetype.h"
array(3) {
[0]=>
string(30) "#include "freetype/freetype.h""
[1]=>
string(19) "freetype/freetype.h"
}
So how do I keep ereg() from thinking the first set of parentheses
is a substring to export. In addition, how do I craft the $regexp to
recognize the first input $line? I came up with the above $regexp lines
by using kregexpeditor in kde.
Navigation:
[Reply to this message]
|