substr voor woorden

Gestart doorMilan2 reacties52 weergaven

3 berichten · pagina 1 van 1

Milan

Lid · Topicstarter

Berichten
8.602
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Hey,

Weet iemand een functie die hetzelfde doet als substr, maar dan met woorden?

Groet,
Milan
0
Berichten
3.788
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Je zou een eigen functie maken die eerst via explode alles opbreekt op spaties en vervolgens een meet loop achtige constructie waardoor je een aantal woorden krijgt

EDIT:
Zoeits dan denk ik, heb het alleen niet getest

[COLOR= #0000BB]<?php[/COLOR]
[COLOR= #007700]function[/COLOR] subWord[COLOR= #007700]([/COLOR][COLOR= #0000BB]$string[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$start[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]0[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$stop[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000]"AUTO"[/COLOR][COLOR= #007700]){[/COLOR]
    [COLOR= #0000BB]$result[/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/if"]if[/URL][COLOR= #007700](![/COLOR][URL="http://www.php.net/is_numeric"]is_numeric[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$start[/COLOR][COLOR= #007700]) ||[/COLOR] [COLOR= #0000BB]$start[/COLOR] [COLOR= #007700]<[/COLOR] [COLOR= #0000BB]0[/COLOR][COLOR= #007700]){[/COLOR] [COLOR= #0000BB]$start[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]0[/COLOR][COLOR= #007700]; }[/COLOR]
    [URL="http://www.php.net/if"]if[/URL][COLOR= #007700](![/COLOR][URL="http://www.php.net/is_numeric"]is_numeric[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$stop[/COLOR][COLOR= #007700]) ||[/COLOR] [COLOR= #0000BB]$start[/COLOR] [COLOR= #007700]<=[/COLOR] [COLOR= #0000BB]$stop[/COLOR][COLOR= #007700]){[/COLOR] [COLOR= #0000BB]$stop[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/count"]count[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$result[/COLOR][COLOR= #007700]); }[/COLOR]
    
    [COLOR= #0000BB]$i[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$start[/COLOR][COLOR= #007700];[/COLOR]
    [COLOR= #0000BB]$string[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000]""[/COLOR][COLOR= #007700];[/COLOR]
    [URL="http://www.php.net/while"]while[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$i[/COLOR] [COLOR= #007700]<[/COLOR] [COLOR= #0000BB]$stop[/COLOR][COLOR= #007700]){[/COLOR]
        [COLOR= #0000BB]$string[/COLOR] [COLOR= #007700].=[/COLOR] [COLOR= #0000BB]$result[/COLOR][COLOR= #007700][[/COLOR][COLOR= #0000BB]$i[/COLOR][COLOR= #007700]].[/COLOR][COLOR= #DD0000]" "[/COLOR][COLOR= #007700];[/COLOR]
        [COLOR= #0000BB]$i[/COLOR][COLOR= #007700]++;
    }[/COLOR]
    [URL="http://www.php.net/return"]return[/URL] [COLOR= #0000BB]$string[/COLOR][COLOR= #007700];
}[/COLOR]
?>
0
Berichten
13.482
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Je bent de $i++ vergeten..
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