Not so long time ago, I asked you for help with preg_match().
Pritaeas gave me nice answer and Cereal showed me nice webpage where I could try out the latest queries, live. The query provided seems to be working on the website granted, but not on my project. 4 out of 6 "hits" are triggered, even though all 6 are supposed to hit.

I can only modify index.php. I couldn't try anything, because it is supposed to hit. Unless I messed up somehow (obviously I did).
http://s000.tinyupload.com/?file_id=83224890448780662681 (click the name)

May I ask you for help on fixing this bug, by explaining what's causing it?

Notice message at the top, is supposed to be there, I still need to code yet.

Member Avatar for diafol

Can.t you post code here? Pointing to a filehost is all well and good. But zips make me nervous if I don.t know the source. Also files on filehost are ysually temporary so a missing file could kill the thread for anybody perusing the thread in the future.

Unfortunately I can't. Two reasons for that, here's one (DaniWeb), the second is that the script is dependant on 2 files (if not 3 or 4). Pasting it here would be quite a mess.
The code "box". Doesn't support standard right-click menu.
Kinda sucks I can't upload attachments :|

I gather what you mean, but I can't :(
The only thing I can do is place the file somewhere more permanent. But thus far I haven't found reliable hosting.

By changing line 50 with:

return array_map('trim', $z);

you avoid new lines in the ParseVariables() generated array and let the regular expression match the pattern.

A problem I see is an undefined index at line 60, which is:

$toReplaceTemplate[$index] = str_replace($contentFrom, $replaceDict[$indexToGo], $toReplaceTemplate[$index]);

And in particular is caused by $replaceDict[$indexToGo]. The $indexToGo matches ++VAR++ and your class is not checking the exceptions, so you could do:

"exceptions"        => array("VAR")

At line 11, then at line 58:

$indexToGo = str_replace("++", "", $output[0]);
if(in_array($indexToGo, $options['exceptions']))
    continue;

You have to add also global $options, but I would avoid such and move the options array to constructor.

You can see the diff here: http://www.mergely.com/f2MpuXAB/

commented: *sniff* *sniff* Did I smell, knowledge? +0

Before slamming solution into my editor, I'd like to ask you some questions (looking at your modifications). I want to learn it and understand it, instead of braindead-ily copy-paste everything.

[snap! deleted two questions, after some thinking I understood]

Line 56, you said:

By changing line 50 with:
return array_map('trim', $z);
you avoid new lines in the ParseVariables() generated array and let the regular expression match the pattern.

it's stupid, but I can't understand what you mean, could you shine some more light on it? Are there any changes in outcome or something?

Also, I didn't know I could globalize the variables directly in the class! Thanks for informing me.

Edit: Also thanks for solving 3 problems I planned to work on after this one got solved (wow, that sounded really rude).

Line 30, $options = array(). Why did you need to declare $options as a parameter?

The constructor works like a function, so you have to declare the expected parameters, as example when you call:

$sys = new Engine(array('abc'));

In the class you need:

class Engine {

    public function __construct($data)
    {
        # work with $data
    }

I added a default value $options = array() in case Engine is defined without a parameter:

$sys = new Engine;

But it would raise warnings, as there will be some undefined indexes. It's up to you to define the behaviour of the class, so you can decide to check if the parameter exists and if it's an array and if the indexes are those expected...

I can't understand what you mean, could you shine some more light on it? Are there any changes in outcome or something?

With your current code:

return $z;

You get:

Array
(
    [IMAGES2] => image3.jpg,image2.jpg,image1.jpg

    [IMAGES] => image1.jpg,image2.jpg,image3.jpg

    [TITLE] => Job=test

)

Which apparently is correct, but each index is spaced by a carriage return. By replacing that return with:

return array_map('trim', $z);

You get:

Array
(
    [IMAGES2] => image3.jpg,image2.jpg,image1.jpg
    [IMAGES] => image1.jpg,image2.jpg,image3.jpg
    [TITLE] => Job=test
)

This reflects in the first $toReplaceTemplate array, the result will change, as with your code the unmatched expressions were looking like:

[10] =>         --for image1.jpg,image2.jpg,image3.jpg
 as IMAGE--

With my suggestion they will change to:

[10] =>         --for image1.jpg,image2.jpg,image3.jpg as IMAGE--

And the /--(.*?)--/ pattern will work as expected.

commented: Thanks! +0
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.