0

I'm developing a PHP script which use the preg_split function. In my computer, using EasyPhp everything works but when I put the files on-line on a free space the function preg_split seems not to work (I have no error message on the screen but the string is not splitted). Is it possibile that this function have been disabled? The version of PHP is PHP 5.2.17 - Optimized for AlterVista so the function should works...is there any alternatives?

The script is made to transform a *.pdf file (saved as a *.txt file) which contains a list of value with the same structure in every page. The following is an example.

Page 1: This is the today harvest. Day: 01/12/2012 Apple 12 Bananas 14 Kiwi 2

Page 2: This is the today harvest. Day: 02/12/2012 Apple 19 Bananas 36 Kiwi 0

Page 3: This is the today harvest. Day: 03/12/2012 Apple 1 Bananas 1 Kiwi 73

The original document contains almost 50 different fruits and have a more complex structure, this is just a simple example of the achievement and the reasons why I am using Regex. I use the following code to create an array named $document_pg where every element is a page of the original document.

$document_pg = preg_split("(This is the today harvest.)", $document);

then I use some a couple of preg_match function to extract the numbers that are wrote on the left of the fruit name. These values will be saved in a database.

Nicolaesse
  • 2,554
  • 12
  • 46
  • 71
  • 1
    What's the regex? This information is necessary for us to tell which alternatives are available to you. – Tim Pietzcker Mar 03 '13 at 21:18
  • 1
    server providers do sometimes disable certain PHP funcs, but preg_split... nah. I don't think so. disabling the preg_split function is completely implausible. In any case, if the function had been disabled, you would get an error saying so; it wouldn't just not split it and carry on. There's almost certainly something else going on here, but can't help you work it out without seeing your actual code. – Spudley Mar 03 '13 at 21:23
  • Oh, and do the `preg_match()` calls work? – Tim Pietzcker Mar 03 '13 at 21:35
  • no, it doesn't. I wrote to the server help desk asking the question. I look forward for their answer. I can't understad why they should disabled the regex functions... – Nicolaesse Mar 03 '13 at 21:40
  • Did you try the `ereg` split I proposed in my answer? – Tim Pietzcker Mar 03 '13 at 21:42
  • Thanks everyone. I didn't completely understand what was wrong but the problem was not the preg_split function, which is enabled, as many simple scripts from http://php.net/manual/en/function.preg-split.php work good. The suggestion of @TimPietzcker was correct but maybe for the same reason doesn't work too. I am quite sure the problem is that when I load the txt file into the string variable, all the line interrupts are deleted and my regex doesn't match properly what I want. I can't understand why it works with EasyPhp and not on-line...but it's not a problem. Thanks again everyone! – Nicolaesse Mar 04 '13 at 21:01

2 Answers2

1

Although it's fairly difficult to say without checking with the hosting provider in question - odds are that the displaying of warnings has been turned off as well by this provider. When this function is disabled it generates a warning level notice which you probably aren't seeing.

To answer your question - it is entirely possible via php ini file to disable functions like this . See here disable_functions

GeoffK
  • 70
  • 6
1

It may be that PHP on your server has been compiled --without-pcre-regex (PCRE only has been mandatory since 5.3.0), so your only option may be to use the deprecated ereg regex functions. Does the following work?

$document_pg = split('(This is the today harvest\.)', $document);
Tim Pietzcker
  • 328,213
  • 58
  • 503
  • 561