Kleine moeite om te zorgen dat regels die op een tag eindigen niet meegenomen mogen wordenquote:Op woensdag 17 september 2008 18:04 schreef slakkie het volgende:
je behoudt indentation, maar je breekt andere dingen:
[ code verwijderd ]
[ code verwijderd ]
1 2 3 | How is your world today? |
1 2 3 4 | <td>Hello _world_</td> <td>Hello world</td> </tr> |
1 2 3 4 5 6 7 8 9 10 | $str = '<tr> <td>Hello _world_</td> <td>Hello world</td>world world </tr>'; $str = preg_replace('/([^_])world([^_])/', '$1hoi!$2', $str); echo $str ?> |
1 2 3 4 5 | <td>Hello _world_</td> <td>Hello hoi!</td>hoi! hoi! </tr> |
http://nl.php.net/manual/en/intro.filter.phpquote:Op donderdag 18 september 2008 @ 12:51 schreef Chandler het volgende:
Ik ben dus al aardig op de goede wegen hoe is het mogelijk om alle karakters te blokken behalve tekstuele tekens??
1 |
1 2 3 4 5 6 7 8 9 10 11 | \n linefeed (LF or 0x0A [img]http://forum.fok.nl/templates/foksilver/i/p/10.gif[/img] in ASCII) \r carriage return (CR or 0x0D [img]http://forum.fok.nl/templates/foksilver/i/p/13.gif[/img] in ASCII) \t horizontal tab (HT or 0x09 (9) in ASCII) \v vertical tab (VT or 0x0B [img]http://forum.fok.nl/templates/foksilver/i/p/11.gif[/img] in ASCII) (since PHP 5.2.5) \f form feed (FF or 0x0C [img]http://forum.fok.nl/templates/foksilver/i/p/12.gif[/img] in ASCII) (since PHP 5.2.5) \\ backslash \$ dollar sign \" double-quote \[0-7]{1,3} the sequence of characters matching the regular expression is a character in octal notation \x[0-9A-Fa-f]{1,2} the sequence of characters matching the regular expression is a character in hexadecimal notation |
Of bijvoorbeeldquote:Op donderdag 18 september 2008 13:10 schreef Chandler het volgende:
Ik doelde op alle karakters behalve de tekstuele en nummerieke.
Hmm, nu kom ik achter een slash in de tekst niet mogelijk is :D ik dacht dit te verhelpen door er een \ voor te zetten maar dat werkt niet? anyone?
1/2Procent
[ code verwijderd ]
Bij welke karakters moet escapen? of hoe?
1 |
In principe "moet" je een regexp binnen /'es plaatsen: /regexp/, maar je mag het ook binnen # plaatsen, mits je dezelfde characters gebruikt. Als je bijv. een regexp met #regexp# klopt hoef je de / niet te escapen, dus ipv: /\/var\/log\/bla/ kan je dan #/var/log/bla# gebruiken. Zie http://perldoc.perl.org/perlretut.html (onder part 1 basic). Ik heb het zo 123 niet kunnen vinden in de PHP documentatie.quote:Op donderdag 18 september 2008 21:56 schreef Chandler het volgende:
huh? heb je ook een beschrijving van de #?
In PHP mag je in principe alles gebruiken, behalve de backslash (\) en alfanumerieke tekens. Zie ook http://nl.php.net/manual/en/intro.pcre.phpquote:Op donderdag 18 september 2008 22:19 schreef slakkie het volgende:
[..]
In principe "moet" je een regexp binnen /'es plaatsen: /regexp/, maar je mag het ook binnen # plaatsen, mits je dezelfde characters gebruikt. Als je bijv. een regexp met #regexp# klopt hoef je de / niet te escapen, dus ipv: /\/var\/log\/bla/ kan je dan #/var/log/bla# gebruiken. Zie http://perldoc.perl.org/perlretut.html (onder part 1 basic). Ik heb het zo 123 niet kunnen vinden in de PHP documentatie.
Dat staat gewoon in de introductie :Pquote:Op donderdag 18 september 2008 22:19 schreef slakkie het volgende:
Ik heb het zo 123 niet kunnen vinden in de PHP documentatie.
quote:The expression must be enclosed in the delimiters, a forward slash (/), for example. Any character can be used for delimiter as long as it's not alphanumeric or backslash (\)
1 |
1 |
Daar heb ik niet gekeken, zat hier te gluren: http://nl2.php.net/manual/en/reference.pcre.pattern.syntax.phpquote:Op donderdag 18 september 2008 22:45 schreef SuperRembo het volgende:
Dat staat gewoon in de introductie
niet dat het in de verste verte maar iets met PHP of MySQL te maken heeft, maar als je alle declaraties voor een psuedo-class ook aan de gewone class meegeeft, zal er weinig veranderen inderdaad.quote:Op vrijdag 19 september 2008 @ 03:22 schreef Cracka-ass het volgende:
Kan iemand mij vertellen waarom mijn button 'active' blijft? Hij blijft altijd ingedrukt zodra ie eenmaal is aangeklikt:
[ code verwijderd ]
Ok, thanks.quote:Op vrijdag 19 september 2008 06:42 schreef slakkie het volgende:
Oftewel, stel je css vragen hier: [CSS] voor dummies - deel 9
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | for ($x = 0; $x < $items; $x++) { $list = mysql_fetch_object($query); $searchFor[] = '#([^_])' . $list->zoek . '([^_])#'; $searchFor[] = '#([^_])' . ucFirst(strtolower($list->zoek)) . '([^_])#'; $searchFor[] = '#([^_])' . strtolower($list->zoek) . '([^_])#'; $replace[] = '$1' . $list->vervang . '$2'; $replace[] = '$1' . $list->vervang . '$2'; $replace[] = '$1' . $list->vervang . '$2'; $text = preg_replace($searchFor, $replace, $text); } ?> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | for ($x = 0; $x < $items; $x++) { $list = mysql_fetch_object($query); $searchFor[] = '#([^_])' . $list->zoek . '([^_])#'; $searchFor[] = '#([^_])' . ucFirst(strtolower($list->zoek)) . '([^_])#'; $searchFor[] = '#([^_])' . strtolower($list->zoek) . '([^_])#'; $replace[] = '$1' . $list->vervang . '$2'; $replace[] = '$1' . $list->vervang . '$2'; $replace[] = '$1' . $list->vervang . '$2'; } $text = preg_replace($searchFor, $replace, $text); ?> |
Je kunt kijken of case insensitve searches sneller zijn als drie losse. Verder kun je proberen je [^_]'s te vervangen door assertions ik kan me voorstellen dat met name die eerste sneller werkt als assertionquote:Op vrijdag 19 september 2008 11:03 schreef Chandler het volgende:
Mensen, ik heb een vraag over preg_replace, het is nogal een slome functieis er ook een manier om het sneller te maken? want ik moet namelijk ruim 600 queries doen met preg_replace en dit duurt echt eeuwen!
Ik heb 50% besparing weten te behalen
oude structuur
[ code verwijderd ]
nieuwe structuur:
[ code verwijderd ]
Maar volgens mij kan het nóg sneller!!!
quote:Assertions
An assertion is a test on the characters following or preceding the current matching point that does not actually consume any characters. The simple assertions coded as \b, \B, \A, \Z, \z, ^ and $ are described above. More complicated assertions are coded as subpatterns. There are two kinds: those that look ahead of the current position in the subject string, and those that look behind it.
An assertion subpattern is matched in the normal way, except that it does not cause the current matching position to be changed. Lookahead assertions start with (?= for positive assertions and (?! for negative assertions. For example, \w+(?=;) matches a word followed by a semicolon, but does not include the semicolon in the match, and foo(?!bar) matches any occurrence of "foo" that is not followed by "bar". Note that the apparently similar pattern (?!foo)bar does not find an occurrence of "bar" that is preceded by something other than "foo"; it finds any occurrence of "bar" whatsoever, because the assertion (?!foo) is always TRUE when the next three characters are "bar". A lookbehind assertion is needed to achieve this effect.
Lookbehind assertions start with (?<= for positive assertions and (?<! for negative assertions. For example, (?<!foo)bar does find an occurrence of "bar" that is not preceded by "foo". The contents of a lookbehind assertion are restricted such that all the strings it matches must have a fixed length. However, if there are several alternatives, they do not all have to have the same fixed length. Thus (?<=bullock|donkey) is permitted, but (?<!dogs?|cats?) causes an error at compile time. Branches that match different length strings are permitted only at the top level of a lookbehind assertion. This is an extension compared with Perl 5.005, which requires all branches to match the same length of string. An assertion such as (?<=ab(c|de)) is not permitted, because its single top-level branch can match two different lengths, but it is acceptable if rewritten to use two top-level branches: (?<=abc|abde) The implementation of lookbehind assertions is, for each alternative, to temporarily move the current position back by the fixed width and then try to match. If there are insufficient characters before the current position, the match is deemed to fail. Lookbehinds in conjunction with once-only subpatterns can be particularly useful for matching at the ends of strings; an example is given at the end of the section on once-only subpatterns.
Several assertions (of any sort) may occur in succession. For example, (?<=\d{3})(?<!999)foo matches "foo" preceded by three digits that are not "999". Notice that each of the assertions is applied independently at the same point in the subject string. First there is a check that the previous three characters are all digits, then there is a check that the same three characters are not "999". This pattern does not match "foo" preceded by six characters, the first of which are digits and the last three of which are not "999". For example, it doesn't match "123abcfoo". A pattern to do that is (?<=\d{3}...)(?<!999)foo
Het is natuurlijk ook geen handig syteem als elk woord mogelijk vervangen kan worden, behalve als er een underscore voor en achter staat. Kan je dat niet omdraaien? Dat zou vele malen sneller zijn.quote:Op vrijdag 19 september 2008 11:03 schreef Chandler het volgende:
Maar volgens mij kan het nóg sneller!!!
array_map("round",$Array);quote:Op dinsdag 23 september 2008 11:52 schreef Chandler het volgende:
Hoe kan ik simpel alle values in een array afronden? zonder foreach oid te gebruiken? ik heb al gekeken bij array_walk / array_map maar kan daar weinig uit wijs worden. Kan iemand mij vertellen welke functie te gebruiken is met verwijzing naar een voorbeeld oid?
Forum Opties | |
---|---|
Forumhop: | |
Hop naar: |