Xojo NthField() and CountFields() functions in PHP

In Xojo there is a handy function I use quite a lot for getting substrings between given delimiters from a piece of text, it is: NthField(text, delimiter, fieldnumber) Imagine you have the following text “1/2/3/4”, NthField( “1/2/3/4”, “/”, 3 ) will return 3, that is the third substring between the “/” delimiters. It is that simple! This function works great in Xojo as long as the text is not too big. A few years ago I was porting a Xojo function to PHP that used NthField() so I decided to port the whole function. This is the PHP equivalent: function …

Continue Reading

Array of arrays

In PHP you can use arrays of arrays. This is a very convenient way to store data for later manipulation. This is an example of an array with 2 web records: $urls = array(); $url = array( “Full” => “[URL http://www.maxprog.com]Maxprog[/URL]”,               “URL”  => “http://www.maxprog.com”,               “Text” => “Maxprog”               ); $urls[] = $url; $url = array( “Full” => “[URL http://www.apple.com]Apple[/URL]”,               “URL”  => “http://www.apple.com”,               “Text” => “Apple”               ); $urls[] = $url; You can format the output this way: foreach( $urls as $url ){     echo “<a href=\””. $url[‘URL’] . “\”>” . $url[‘Text’] . “</a><br>\n”; } The result will be: <a href=”http://www.maxprog.com”>Maxprog</a><br> <a href=”http://www.apple.com”>Apple</a><br> You can try …

Continue Reading
FILED UNDER: PHPTAGGED WITH: