PHP preg_match

Gestart doorAntonn16 reacties50 weergaven

17 berichten · pagina 1 van 2

Antonn

Lid · Topicstarter

Berichten
8.649
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Yo luitjez biggrin
Ik wil kijken op een van deze ( /:*?"<>| ) symbolen in een string voorkomen. En aangezien dat preg_match niet mijn beste vak ik hoopte ik dat hier wel ergens een fantastish persoon(/.....) zou zitten die dit voor mij zou willen voorkouwen.

Bedankt heartheartheartheartheartheartheartheartheartheartheartheartheartheartheartheartheartheartheartheartheartheartheartheart
GREETZ smile
0
Berichten
11.263
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Je kan het ook met stristr()

Hier heb je een voorbeeld met een apenstaartje:

[COLOR= #0000BB]<?php
$string[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000]"Ikbensander@hotmail.com"[/COLOR][COLOR= #007700];[/COLOR]

[URL="http://www.php.net/if"]if[/URL] [COLOR= #007700]([/COLOR][URL="http://www.php.net/stristr"]stristr[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$string[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #DD0000]@[/COLOR][COLOR= #007700]))
{[/COLOR]
    [URL="http://www.php.net/echo"]echo[/URL][COLOR= #DD0000] Er staat een apenstaartje in[/COLOR][COLOR= #007700];
}[/COLOR]
[URL="http://www.php.net/else"]else[/URL]
[COLOR= #007700]{[/COLOR]
    [URL="http://www.php.net/echo"]echo[/URL][COLOR= #DD0000] Er staat geen apenstaartje in[/COLOR][COLOR= #007700];
}[/COLOR]
?>
0
Antonn

Lid · Topicstarter

Berichten
8.649
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Sanderc schreef:
Je kan het ook met stristr()

Hier heb je een voorbeeld met een apenstaartje:
[COLOR= #0000BB]<?php
$string[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000]"Ikbensander@hotmail.com"[/COLOR][COLOR= #007700];[/COLOR]

[URL="http://www.php.net/if"]if[/URL] [COLOR= #007700]([/COLOR][URL="http://www.php.net/stristr"]stristr[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$string[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #DD0000]@[/COLOR][COLOR= #007700]))
{[/COLOR]
    [URL="http://www.php.net/echo"]echo[/URL][COLOR= #DD0000] Er staat een apenstaartje in[/COLOR][COLOR= #007700];
}[/COLOR]
[URL="http://www.php.net/else"]else[/URL]
[COLOR= #007700]{[/COLOR]
    [URL="http://www.php.net/echo"]echo[/URL][COLOR= #DD0000] Er staat geen apenstaartje in[/COLOR][COLOR= #007700];
}[/COLOR]
?>


if (strpos($_POST[name], "") !== false || strpos($_POST[name], "/") !== false || strpos($_POST[name], ":") !== false || strpos($_POST[name], "*") !== false || strpos($_POST[name], "?") !== false || strpos($_POST[name], """) !== false || strpos($_POST[name], "<") !== false || strpos($_POST[name], ">") !== false || strpos($_POST[name], "|") !== false) {

Dat had ik eerst. Dat is niet echt de bedoeling...
0
Thom

Lid

Berichten
10.654
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Antonn schreef:
Eerdere citaten tonen
Sanderc schreef:
Je kan het ook met stristr()
Hier heb je een voorbeeld met een apenstaartje:

[COLOR= #0000BB]<?php
$string[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000]"Ikbensander@hotmail.com"[/COLOR][COLOR= #007700];[/COLOR]

[URL="http://www.php.net/if"]if[/URL] [COLOR= #007700]([/COLOR][URL="http://www.php.net/stristr"]stristr[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$string[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #DD0000]@[/COLOR][COLOR= #007700]))
{[/COLOR]
    [URL="http://www.php.net/echo"]echo[/URL][COLOR= #DD0000] Er staat een apenstaartje in[/COLOR][COLOR= #007700];
}[/COLOR]
[URL="http://www.php.net/else"]else[/URL]
[COLOR= #007700]{[/COLOR]
    [URL="http://www.php.net/echo"]echo[/URL][COLOR= #DD0000] Er staat geen apenstaartje in[/COLOR][COLOR= #007700];
}[/COLOR]
?>

if (strpos($_POST[name], "") !== false || strpos($_POST[name], "/") !== false || strpos($_POST[name], ":") !== false || strpos($_POST[name], "*") !== false || strpos($_POST[name], "?") !== false || strpos($_POST[name], """) !== false || strpos($_POST[name], "<") !== false || strpos($_POST[name], ">") !== false || strpos($_POST[name], "|") !== false) {

Dat had ik eerst. Dat is niet echt de bedoeling...

waarom !== false? dat maakt het alleen maar langer
0
Antonn

Lid · Topicstarter

Berichten
8.649
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Thommity schreef:
Eerdere citaten tonen
Antonn schreef:
Eerdere citaten tonen
Sanderc schreef:
Je kan het ook met stristr()
Hier heb je een voorbeeld met een apenstaartje:

[COLOR= #0000BB]<?php
$string[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000]"Ikbensander@hotmail.com"[/COLOR][COLOR= #007700];[/COLOR]

[URL="http://www.php.net/if"]if[/URL] [COLOR= #007700]([/COLOR][URL="http://www.php.net/stristr"]stristr[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$string[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #DD0000]@[/COLOR][COLOR= #007700]))
{[/COLOR]
    [URL="http://www.php.net/echo"]echo[/URL][COLOR= #DD0000] Er staat een apenstaartje in[/COLOR][COLOR= #007700];
}[/COLOR]
[URL="http://www.php.net/else"]else[/URL]
[COLOR= #007700]{[/COLOR]
    [URL="http://www.php.net/echo"]echo[/URL][COLOR= #DD0000] Er staat geen apenstaartje in[/COLOR][COLOR= #007700];
}[/COLOR]
?>

if (strpos($_POST[name], "") !== false || strpos($_POST[name], "/") !== false || strpos($_POST[name], ":") !== false || strpos($_POST[name], "*") !== false || strpos($_POST[name], "?") !== false || strpos($_POST[name], """) !== false || strpos($_POST[name], "<") !== false || strpos($_POST[name], ">") !== false || strpos($_POST[name], "|") !== false) {

Dat had ik eerst. Dat is niet echt de bedoeling...
waarom !== false? dat maakt het alleen maar langer


Je kan niet === TRUE gebruiken. Want hij geeft een ....


Daar heb je punt emo Maar wat boeit het. Zo hoort het toch al niet. Het moet met preg_match geloof ik. Dat is in ieder geval de beste/snelste optie.
0
Berichten
5.957
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
of gewoon if(strpos() || strpos() || strpos())
0
Antonn

Lid · Topicstarter

Berichten
8.649
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Alemaalte schreef:
of gewoon if(strpos() || strpos() || strpos())
Kijk post boven je. Dat had ik eerst en werkte niet. Toen kreeg ik een vage error. Maar dit moet toch met preg_match, of vergis ik me?
0
Berichten
35.796
Reputatie
1
Punten
0,00
Lid sinds
Laatst gezien
Omdat ik ook geen baas ben met die reguliere expressies zou ik het zo doen:

[COLOR= #0000BB]<?php
$array[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/array"]array[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]/[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #DD0000]:[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #DD0000]*[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #DD0000]?[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #DD0000][/COLOR][COLOR= #007700],[/COLOR] [COLOR= #DD0000]"[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #DD0000]<[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #DD0000]>[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #DD0000]|[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #DD0000][/COLOR][COLOR= #007700]);[/COLOR]

[URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/str_replace"]str_replace[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$array[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #DD0000][/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$str[/COLOR][COLOR= #007700]) !=[/COLOR] [COLOR= #0000BB]$str[/COLOR][COLOR= #007700])[/COLOR]
    [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]een van die dingen kwam er in voor[/COLOR][COLOR= #007700];[/COLOR]


maar als iemand een regexp kan bouwen dan kun je dat beter doen
0
Berichten
832
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
gewoon

[COLOR= #0000BB]<?php
$string[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000]hoi?[/COLOR][COLOR= #007700];[/COLOR]
[URL="http://www.php.net/if"]if[/URL] [COLOR= #007700]([/COLOR][URL="http://www.php.net/preg_match"]preg_match[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"/[/:*?"<>|]/"[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$string[/COLOR][COLOR= #007700])) {[/COLOR]
    [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]ja ofzo[/COLOR][COLOR= #007700];
}[/COLOR]
[URL="http://www.php.net/else"]else[/URL] [COLOR= #007700]{[/COLOR]
    [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]nee ofzo[/COLOR][COLOR= #007700];
}[/COLOR]
?>
0
Antonn

Lid · Topicstarter

Berichten
8.649
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Lennard schreef:
Omdat ik ook geen baas ben met die reguliere expressies zou ik het zo doen:

[COLOR= #0000BB]<?php
$array[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/array"]array[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]/[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #DD0000]:[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #DD0000]*[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #DD0000]?[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #DD0000][/COLOR][COLOR= #007700],[/COLOR] [COLOR= #DD0000]"[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #DD0000]<[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #DD0000]>[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #DD0000]|[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #DD0000][/COLOR][COLOR= #007700]);[/COLOR]

[URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/str_replace"]str_replace[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$array[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #DD0000][/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$str[/COLOR][COLOR= #007700]) !=[/COLOR] [COLOR= #0000BB]$str[/COLOR][COLOR= #007700])[/COLOR]
    [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]een van die dingen kwam er in voor[/COLOR][COLOR= #007700];[/COLOR]
maar als iemand een regexp kan bouwen dan kun je dat beter doen

Slim gezien
Guillamos schreef:
gewoon

[COLOR= #0000BB]<?php
$string[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000]hoi?[/COLOR][COLOR= #007700];[/COLOR]
[URL="http://www.php.net/if"]if[/URL] [COLOR= #007700]([/COLOR][URL="http://www.php.net/preg_match"]preg_match[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"/[/:*?"<>|]/"[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$string[/COLOR][COLOR= #007700])) {[/COLOR]
    [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]ja ofzo[/COLOR][COLOR= #007700];
}[/COLOR]
[URL="http://www.php.net/else"]else[/URL] [COLOR= #007700]{[/COLOR]
    [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]nee ofzo[/COLOR][COLOR= #007700];
}[/COLOR]
?>
Mijjn held, jij paasbaas pompomthumbsupworshippy
0
Berichten
35.796
Reputatie
1
Punten
0,00
Lid sinds
Laatst gezien
Guillamos schreef:
gewoon

[COLOR= #0000BB]<?php
$string[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000]hoi?[/COLOR][COLOR= #007700];[/COLOR]
[URL="http://www.php.net/if"]if[/URL] [COLOR= #007700]([/COLOR][URL="http://www.php.net/preg_match"]preg_match[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"/[/:*?"<>|]/"[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$string[/COLOR][COLOR= #007700])) {[/COLOR]
    [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]ja ofzo[/COLOR][COLOR= #007700];
}[/COLOR]
[URL="http://www.php.net/else"]else[/URL] [COLOR= #007700]{[/COLOR]
    [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]nee ofzo[/COLOR][COLOR= #007700];
}[/COLOR]
?>
Nice biggrin
0
Berichten
5.957
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Tip
Do not use preg_match() if you only want to check if one string is contained in another string. Use strpos() or strstr() instead as they will be faster.
Dus misschien moet je zelf even testen of die van lennard niet sneller is.
0
Antonn

Lid · Topicstarter

Berichten
8.649
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Alemaalte schreef:
Tip
Do not use preg_match() if you only want to check if one string is contained in another string. Use strpos() or strstr() instead as they will be faster.
Dus misschien moet je zelf even testen of die van lennard niet sneller is.
Het kan inderdaad sneller zijn, maar 9x strpos VS 1x preg_match... Das weer wat anders.
0
Berichten
5.957
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Antonn schreef:
Eerdere citaten tonen
Alemaalte schreef:
Tip
Do not use preg_match() if you only want to check if one string is contained in another string. Use strpos() or strstr() instead as they will be faster.
Dus misschien moet je zelf even testen of die van lennard niet sneller is.

Het kan inderdaad sneller zijn, maar 9x strpos VS 1x preg_match... Das weer wat anders.
Ik ga het eens testen.
0
Berichten
832
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Die van Lennard lijkt sneller te zijn inderdaad.
0.00036999999999998 (mijne) tegen
0.00011800000000006 (lennard)
Al weet ik niet of je 2 milliseconden gaat merken.
0

Jouw reactie

Deel je idee, stel een vraag of help een ander verder.

Editor laden…

Praat mee met de One2xs-community.

Inloggen om te reageren