PHP Classes
elePHPant
Icontem

PHP String Foreach: Process strings as arrays of characters

Recommend this page to a friend!
  Info   View files Example   View files View files (4)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2017-08-04 (3 months ago) RSS 2.0 feedNot yet rated by the usersTotal: 117 All time: 8,701 This week: 662Up
Version License PHP version Categories
m6 1.0.1Custom (specified...5PHP 5, Text processing
Description Author

This class can process strings as arrays of characters.

It provides functions to manipulate given strings that are equivalent to those for manipulating arrays.

Currently it can provides functions like explode, foreach, strposall, strposreplace, strposadd, etc..

Recommendations

Convert Ms Word to plaint text and count number of words
How to count word from plaintext

Get all words in sentence
Some class to get all of words in sentence

What is the best PHP count words class?
Count the number of words in a string

  Performance   Level  
Name: zinsou A.A.E.Mo´se is available for providing paid consulting. Contact zinsou A.A.E.Mo´se .
Classes: 22 packages by
Country: Benin Benin
Age: 28
All time rank: 17381 in Benin Benin
Week rank: 1 Up
Innovation award
Innovation award
Nominee: 5x

Details
Stringforeach  class is a usefull way to handle some actions over the string type of PHP.
It allows user to look and go trough a string just like an array and then make easier the manipulation like
search, replacement, deletion,explosion,case transformation  .








class Stringforeach{
		protected $str, $length;
					public function __construct($string){
						the constructor
					}
					
					public function explodemore ($separate='',$lan='php',$encoding=false){
					can be used to explode the string in array
					$separate can be chosen  in this set of values {word,ponctuation,phrase} or  any string or even a numeric
					when $separate is a numeric the string is split in array of string of which the length is equal to the chosen numeric
					when $separate is a string==word the string will be split in array of words
					when $separate is is a string==ponctuation the string will be split before ponctuation in array of string 
					when $separate is a string==phrase the string will be split in array of phrases.
					when $separate is a string=="" the string will be split in array before any space type character
					when $separate is just any other  string, the method will just act like the function explode of PHP.

					$lan is used to specify if the numbers in the string are in french format with a comma instead of point for float number
						(example: 25.000,025) 
						or if numbers are in english format (example: 25,000.025) or simply in PHP format (example: 25000.025) 
						}
						
					$encoding is used to specify  what encoding should be used to cut the string  if $separate is a numeric
					
					}
					
					public function strforeach(){
						can be used to explode the string in array of characters
					}
					
					public function strposall($s){
						can be used to find all the occurences of the string $s and their precise position in the string
					}
					
					public function strposreplace($s,$s2,$pos){
						can be used to replace  the  occurence of the string $s  in the position $pos by the given string $s2
					}
					
					
				
					public function strposadd($s,$s2,$pos,$before=true){
					can be used to add $before or after  the  occurence of the string $s  in the position $pos , the given string $s2
					}

					
					
					
					public function addstratpos($s,$pos,$before=true){
						can be used to add $before or after   the position $pos , the given string $s
					}
					
					
					public function upper_1stletter(){
						can be used to upper  the first letter of all the phrases contained in the string
					}
					
					
					public function upper_pos($pos){
						can be used to upper  the  letter in the position $pos in the string
					}


					public function lower_pos($pos){
					can be used to lower  the  letter in the position $pos in the string
					}
					
					public function upper_strpos($s,$pos){
						can be used to upper  the occurence of the string $s  in the position $pos in the string
					}
					
					public function lower_strpos($s,$pos){
						can be used to lower  the occurence of the string $s  in the position $pos in the string
					}
					
					public function upper_preciseletter($s){
						can be used to upper all the occurences of the letter $s   in the string
					}
					
					public function lower_preciseletter($s){
						can be used to lower all the occurences of the letter $s   in the string
					}
					
					public function delete_posletter($s,$pos){
						can be used to delete  the occurence of the letter $s  in the position $pos in the string
					}
					
					
					public function delete_pos($pos){
						can be used to delete  the character   in the position $pos in the string
					}
					
					
					public function delete_preciseletter($s){
						can be used to delete all the occurences of the letter $s   in the string
					}
					
					public function delete_strpos($s,$pos){
						can be used to delete  the occurence of the string $s  in the position $pos in the string
					}
					
					
					public function delete_strelements($offset,$length){
						can be used to delete  some string's elements by specifying the starting point $offset and the $length to specify the precise number
						of characters to delete
					}
					
					public function delete_last(){
						can be used to delete  the last character  in the string
					}
					
					public function delete_first(){
						can be used to delete  the first character  in the string
					}
					
					
					public function wordmatches($pattern){
						can be used to control if the given pattern is  in the string
						$pattern must use the pcre language
					}
					
					public function patternsmatches($patterns){
						can be used to control if the given $patterns in array  are in the string
						$patterns must be an array of which each value use the pcre language
					}
					
					public function wordmatchespos($pattern){
					can be used to find all the occurences and the postions of the given pattern   in the string
						$pattern must use the pcre language
					}
					
					public function patternsmatchespos($patterns){
						can be used to find all the occurences and the postions of each given pattern in the array of $patterns  in the string
						$patterns must be an array of which each value use the pcre language
					}
					
					public function len(){
						return the string length
					}
					
					
					
					
					public function numberdetect($lan='php'){
						return the first occurence of special format number in the string and its offset
						$lan is used to specify if the numbers in the string are in french format with a comma instead of point for float number
						(example: 25.000,025) 
						or if numbers are in english format (example: 25,000.025) or simply in PHP format (example: 25000.025) 
				
					}
					
					
					public function allnumberdetect($lan){
						return all the  occurences of special format number in the string and their offset
						$lan is used to specify if the numbers in the string are in french format with a comma instead of point for float number
						(example: 25.000,025) 
						or if numbers are in english format (example: 25,000.025) or simply in PHP format (example: 25000.025) 
					}
}

for some examples of use see the teststrforeach.php script file
bug reporting qnd feeback to leizmo@gmail.com or just use the dedicated forum of the package.
  Files folder image Files  
File Role Description
Accessible without login Plain text file license Lic. license
Accessible without login Plain text file readme.txt Doc. readme
Plain text file strforeach.class.php Class strforeach class source
Accessible without login Plain text file teststrforeach.php Example example script

 Version Control Unique User Downloads Download Rankings  
 0%
Total:117
This week:0
All time:8,701
This week:662Up