-
Posts
1,832 -
Joined
-
Last visited
-
Days Won
3
Everything posted by salathe
-
It would be much more intuitive to be able to do that, I agree. There is no concept of $this or self:: in these anonymous functions. You could pass the object ($foo) through to the function (in place of $this) using use and have Foo:: (in place of self::) but it's not a pretty solution.
-
Also note that you won't be able to call $foo->bar() — you need to use call_user_func($foo->bar) or $foo->bar->__invoke()
-
Just to clarify (it might not be clear for the OP), Daniel's code still does not define the 'bar' method, it assigns an anonymous function to the bar property (which might be fine).
-
I was going to introduce myself, still being fairly new to the community—not too sure I want to now. Back to the regex forum for me. :-\
-
SimpleXMLElement::xpath returns an array, so you could also as an alternative use array_slice() to get only the number of books that you want.
-
CHECH A STRING FOR ' " ' (DOUBLE QUOTES)
salathe replied to salman_ahad@yahoo.com's topic in PHP Coding Help
Give give us the text (just the text, no silly colours or formatting) of "a big article" that is not producing the expected result, for us to test against. Without knowing what input you're dealing with (some of us aren't psychic) it is very difficult to advise you on why things might not be working as expected. Repeating the same problem over and over is not helping us to help you out. -
php -l only checks the syntax of the file, it won't catch runtime errors. Are you sure you want just a syntax check (as your original post says)?
-
Are you sure that all dates follow that pattern? The day number is only allowed one digit.
-
PHP 5 factory method with dynamic parameters
salathe replied to w3evolutions's topic in Application Design
Are you having trouble with any particular part? I'm not seeing where you want us to help you out. -
PHP 5 factory method with dynamic parameters
salathe replied to w3evolutions's topic in Application Design
Perhaps your factory could use Reflection? $ref = new ReflectionClass('Fruits'); $foo = $ref->newInstanceArgs(array('apple', 'banana', 'cherry')); P.S. That essentially calls new Fruits('apple', 'banana', 'cherry'); -
The preg_* function documentation only aims to document the functions themselves, not the patterns which can be provided to those functions. For "those who don't know what all the /wd<>\\n type things mean" there is a series of pages describing the pattern syntax which details everything† you can use to construct a regular expression (though I'll admit, it's pretty dry reading!). If the number of asterisks is important to you, and you really want to use a regular expression (rather than string functions, for example) then the snippet below will do what you're asking but it's not really a "basic" regular expression. $ip = '12.34.123.4'; echo preg_replace('/(?:^(?:\d+\.){2}|)\K\d/', '*', $ip); // 12.34.***.* Another alternative would be to grab the last two octets (what you want to mask) and use a function to filter out the digits. function mask_digits($m) { return preg_replace('/\d/', '*', $m[0]); } echo preg_replace_callback('/\d+\.\d+$/', 'mask_digits', $ip); † "everything" is not quite true, but it's more than enough for most purposes.
-
This is slightly tangential to the current discussion but addressing: Sure, get_defined_functions (in particular the "user" array returned from that; unless I missed your point entirely ).
-
CHECH A STRING FOR ' " ' (DOUBLE QUOTES)
salathe replied to salman_ahad@yahoo.com's topic in PHP Coding Help
Please try. What value of $para gives you only three sentences and how many are you expecting? -
Odd. What does the following give: <?php error_reporting(E_ALL | E_STRICT); date_default_timezone_set('Europe/London'); var_dump( date_default_timezone_get(), ini_get('timezone.default'), getenv('TZ') ); echo date('r');
-
Neither does keldorn's, to be fair. Nor should they.
-
Does echo date('r'); give you the right date and timezone? Is MySQL's timezone set to an American timezone?
-
The following example looks for one or more non-@ characters from the start of the string. (Same as cags's but without the case-insensitive modifier i since that's not necessary) $email = "foo@example.org"; preg_match('/^[^@]+/', $email, $match); echo $match[0]; // foo
-
Out of interest can you tell us what var_dump($monthup, $monthdown) outputs?
-
With PHP 5.3.0 came get_called_class() which might be suitable. <?php class ParentClass { public function test() { if (__CLASS__ != get_called_class()) { echo "Called from child (" . get_called_class() . ")\n"; } else { echo "Called from parent (" . __CLASS__ . ")\n"; } } } class ChildClass extends ParentClass { } class GrandChildClass extends ChildClass { } $parent = new ParentClass; $child = new ChildClass; $grand = new GrandChildClass; $parent->test(); $child->test(); $grand->test(); ?> Called from parent (ParentClass) Called from child (ChildClass) Called from child (GrandChildClass) If not, as Mark said it will probably be a job for debug_backtrace().
-
[SOLVED] Small string..can't get the right combo to pull it in.
salathe replied to Modernvox's topic in Regex Help
I'm not too sure I'd be up for a brain swap (though I'm sure yours is a lovely brain) but keep on posting questions and I'll keep posting replies (and maybe some answers). -
[SOLVED] Small string..can't get the right combo to pull it in.
salathe replied to Modernvox's topic in Regex Help
I can't edit my previous post to provide an example of grabbing the links that you want, so it'll have to be a double-post (sorry if you guys frown on that!). $html = file_get_contents($url); $pattern = '#<a href="(/mcy/\d{10}\.html)">#'; preg_match_all($pattern, $html, $matches); echo "Links:\n"; foreach ($matches[1] as $link) { echo $link . "\n"; } Will output something like (shortened to save scrolling): Links: /mcy/1435866184.html /mcy/1435864882.html /mcy/1435864500.html ... /mcy/1435673391.html /mcy/1435671439.html -
[SOLVED] Small string..can't get the right combo to pull it in.
salathe replied to Modernvox's topic in Regex Help
Generally forward slashes (/), though not if they occur within the pattern (common with parsing URIs or HTML). In the latter case, common alternatives are tilde (~) or hash/pound (#). E.g. /foobar\.html/i /\/foo\/bar\.html/ <-- ugly ~/foo/bar\.html~ -
There is no DateObject in the PHP core, is this a user-defined class or do you mean DateTime? Also, your code snippet only deals with the $date value being not null which won't affect any null value.
-
Offtopic: > Just out of interest, why did you (Daniel0) choose [^>] as the pattern match for the anchor text? Is there a place to discuss this kind of thing (choosing one way or another to do a task) which isn't in pre-existing question threads?