string splitsen

Gestart doorOosterhout4 reacties19 weergaven

5 berichten · pagina 1 van 1

Oosterhout

Lid · Topicstarter

Berichten
88
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Hoe kan ik een string splitsen na de eerste spatie?
Voorbeeld:

$string ="Hoe kan ik een";
//dan moet het volgende eruit komen
$a = "Hoe";
$b = "kan ik een";


Dus niet splitsen na elke spatie maar alleen bij de eerste.
0
Rik

Lid

Berichten
18.393
Reputatie
0
Punten
0,04
Lid sinds
Laatst gezien
Met explode( boundary, string, limit )

Je kunt dan hetvolgende doen:

[COLOR= #0000BB]<?php

$string[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000]Hoe kan ik een[/COLOR][COLOR= #007700];[/COLOR]

[COLOR= #0000BB]$arr[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/explode"]explode[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000] [/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$string[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]2[/COLOR][COLOR= #007700]);[/COLOR]

[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$arr[/COLOR][COLOR= #007700][[/COLOR][COLOR= #0000BB]0[/COLOR][COLOR= #007700]];[/COLOR] [COLOR= #FF8000]// "Hoe"[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$arr[/COLOR][COLOR= #007700][[/COLOR][COLOR= #0000BB]1[/COLOR][COLOR= #007700]];[/COLOR] [COLOR= #FF8000]// "kan ik een"[/COLOR]

?>
0
Oosterhout

Lid · Topicstarter

Berichten
88
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Bedankt! thumbsup
0
Berichten
8.649
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Ook handig:

[COLOR= #0000BB]<?php

$string[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000]Hoe kan ik een[/COLOR][COLOR= #007700];[/COLOR]

[COLOR= #0000BB]$arr[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/explode"]explode[/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= #0000BB]$arr[/COLOR][COLOR= #007700][[/COLOR][COLOR= #0000BB]0[/COLOR][COLOR= #007700]];[/COLOR] [COLOR= #FF8000]// "Hoe"[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$arr[/COLOR][COLOR= #007700][[/COLOR][COLOR= #0000BB]1[/COLOR][COLOR= #007700]];[/COLOR] [COLOR= #FF8000]// "kan"[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$arr[/COLOR][COLOR= #007700][[/COLOR][COLOR= #0000BB]2[/COLOR][COLOR= #007700]];[/COLOR] [COLOR= #FF8000]// "ik"[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$arr[/COLOR][COLOR= #007700][[/COLOR][COLOR= #0000BB]3[/COLOR][COLOR= #007700]];[/COLOR] [COLOR= #FF8000]// "een"[/COLOR]

?>
0
Rik

Lid

Berichten
18.393
Reputatie
0
Punten
0,04
Lid sinds
Laatst gezien
Vriendje schreef:
Ook handig:
[COLOR= #0000BB]<?php

$string[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000]Hoe kan ik een[/COLOR][COLOR= #007700];[/COLOR]

[COLOR= #0000BB]$arr[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/explode"]explode[/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= #0000BB]$arr[/COLOR][COLOR= #007700][[/COLOR][COLOR= #0000BB]0[/COLOR][COLOR= #007700]];[/COLOR] [COLOR= #FF8000]// "Hoe"[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$arr[/COLOR][COLOR= #007700][[/COLOR][COLOR= #0000BB]1[/COLOR][COLOR= #007700]];[/COLOR] [COLOR= #FF8000]// "kan"[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$arr[/COLOR][COLOR= #007700][[/COLOR][COLOR= #0000BB]2[/COLOR][COLOR= #007700]];[/COLOR] [COLOR= #FF8000]// "ik"[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$arr[/COLOR][COLOR= #007700][[/COLOR][COLOR= #0000BB]3[/COLOR][COLOR= #007700]];[/COLOR] [COLOR= #FF8000]// "een"[/COLOR]

?>


Maar daar vroeg hij helemaal niet om. Daar vroeg hij juist niet om.

Quote:
Dus niet splitsen na elke spatie maar alleen bij de eerste.

Dus een beetje een erg onnodige post. Zeker aangezien ik al naar de explode functie linkte, en hij daar zelf dus ook naar kon kijken.
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