Home Products Downloads News Store Support Forums

Stan's Blog

Stan's Blog

Tips and tricks on how to use Maxprog products

Compatible with MS Windows Compatible with MacOS


Xojo NthField() and CountFields() functions in PHP

Topics

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 nthfield($text, $delimiter, $fieldnumber) {
  $data = explode($delimiter, $text . $delimiter );
  return $data[$fieldnumber-1];
}

It is that simple, now you have the exact same NthField() in PHP. That function is fully accurate, I have been using it everywhere in my site for years.

Next I needed the related function to count the number of fields for a given delimiter:

CountFields(text, delimiter)

For the sample text we used above, "1/2/3/4", CountFields( "1/2/3/4", "/" ) would return 4, that is, the number of fields enclosed by the "/" delimiter. This is the PHP equivalent:

function countfields($text, $delimiter) {
  return count(explode($delimiter, $text));
}

As you can see the both functions use simple PHP array functions and since NthField() is slow in Xojo when the text is big, it would be simple to rewrite it :-)



Stan Busk - Software Engineer
at www.maxprog.com






 Rate This Post!
Stan Busk Stan Busk
November 9, 2017



Recent questions from our users
  iCash file size grew up over 120 Mb New Screenshot
  Need help installing MLM on server New Screenshot
  What are your payment methods New
  Images not displaying in Preview after update to 8.7 New
  Not able to verify anything New Screenshot
  How to send an email with a picture in the body New YouTube Video
  Images are missing in the message preview New
  Bad Gmail addresses marked as valid New Screenshot
  Amazon SES (correct) settings New Screenshot
  Importing Bank statements into iCash New
  Picture with text on the right New YouTube Video
  Error with every email-adress (even my own, working one) New
  Not receiving the Delivery Report New YouTube Video
  I've tried to download the latest version for 3 days... Update
  Nothing is downloaded Update
  MLM Unsubscribe feature Update
  Spaces disappearing when using the Styled Text format Update
  Email editor and responsive emails Update
  Text disappearing when previewing and sending Update
  How does eMail Verifier compares to online services? Update
  About eMail Extractor privacy Update
  BCC sending mail merge email Update
  Question about your software Update
  Accessing the MaxBulk Mailer black list Update
  Scanning a subfolder rather than the entire inbox Update
  Erreur #103: Le URL n'est pas valide Update
  Cambiar de macOS a Windows Update
  Maxbulk - switching computers Update
  Stalled - Infinite Loop Update
  Unable to import my contacts into MaxBulk Mailer Update YouTube Video
  Setting DKIM for the first time
  MLM Unsubscribe Link Screenshot
  The application is crashing
  Authentication errors...
  Cannot authenticate with Gmail YouTube Video
  Desactualizado 32 bits a 64 bits
  Importing a csv/txt file YouTube Video
  Using eMail Bounce Handler
  Importing recipients from a text file YouTube Video
  The program does not verify any address
  Importing accounting data from Quicken
  Error cargando iCash "v4rb_x64.dll"
  TLS1.2 support
  eMail Verifier is timing out
  Upgrading 8.5 to 8.6
  Creating submaps
  Unexpected Blacklisting
  Comcast residential bulk limits
  HostGator delivery limits
  Someone using your software is sending SPAM
  Mise à jour vers 8.6.1
  Quelle est la différence entre iCash et iCash SE?
  Error in the installation 'api-ms-win-crt-heap-l1-1-0.dll is missing
  Bad e-mail addresses are sometimes marked as valid
  Lately all my emails are going into the recipients spam folder
  Resend Registration Licenses
  Mail-merge sender data using tags YouTube Video
  How to embed a photo into the email text
  Not working Error #22
  MX record not found
  Messages says delivered but I haven't received it
  Lost emails
  Custom Attachments
  TLS 1.2 Support
  Upgrade MaxBulk Mailer SE to Pro
  I purchased the product and did not receive the serial number
  Reconciled amount is wrong
  Can't send emails thru Gmail YouTube Video
  No puedo registrar mi número de Licencia.
  Where are the delivery logs?
  Most of my messages are rejected
  Activation Key
  Earthlink changed settings and MailBulk Mailer does not work
  Missing a lot of messages and labels in Italian
  eMail Verifier speed and capacity
  Using the List function
  No consigo que envíe mails. SSL
  Sending to a maximum of 300 e-mails per hour
  Using eMail Bounce Handler with eMail Verifier
  My customers are not receiving my messages
  Last update broke everything...
  Recuperar Maxbulk Mailer SE
  Icash update
  Wont print Anything
  MaxBulk Mailer no longer sending links
  Empty folder after download
  Fallo cierre programa
  Someone is illegally using your software with my email address.
  Mensaje de error al cerrar la aplicación
  MaxBulk Mailer SE
  eMail Verifier is only able to test Gmail addresses
  Plan de actualización
  New download wont open
  No se ejecuta el programa
  Custom Max Bulk / Adding new features
  Someone is spoofing my email address to send spam
  eMail Extractor not working properly on my computer
  Email Verifier vs online verifers
  How can I use my update plan on a new computer?
  Why do I get a Delivery Report message after each delivery?
  What mail server can I use with MaxBulk Mailer?
  Subject Command Tag YouTube Video
  PDF attachments not received
  Remote lists
  Déplacement/copie de contacts entre documents
  MLM upload gives 0 address(es) have been uploaded to 'List'
  Where to find the log files of Maxprog Bulk Mailer
  Exporting data does not include past sent information
  Unsubscribe with text file does not update remote list
  Problemas de verificación
  Result file takes long to appear
  Max Bulk Mailer crashes every time after send 100-150 emails
  Can't find my activation key
  eMail Verifier is Hanging up
  Authentication failed / Relaying error
  64bit version of iCash
  How do I turn of Click Tracking ? in Plain Text?
  eMail Extractor y mensajes en Outlook
  Desaparición de datos
  I have misplaced my activation key for eMail Extractor
  The program found no email addresses
  Computer crashed, trying to rebuild mailing lists and preferences
  MLM URLs don't work
  Creating a remote list
  No files in File Manager
  How can I update from iCash 7.5.3 (App Store) to 7.6.x
  Your Kind Assistance Please!
  Word docs with weblinks
  La page web reçue est différente de celle envoyée avec mbm
  Erreur de n° de série
  The software asks for an account ID and password
  Forwarding emails sent by MaxBulk, cut and paste not working
  MLM cannot connect
  Lost serial
  Freezes after pref change
  Resend/Recall Function
  Slow loading iCash data files
  Where are the logs?
  Won't send any emails
  Deal of the day is not applied
  My computer rebooted and i lost my serial number
  Transferring recipient lists between two MaxBulk Mailer copies
  Computar cuotas de hipoteca como gasto en los informes
  Won't verify lists
  Links not working
  MacOS 10.13 High Sierra
  64-bit version of iCash availability
  Je n'arrive pas à envoyer mon message à toute ma liste en une fois
  Quels sont mes identifiants MLM? Screenshot
  DMARC Evaluation error
  Where are the preferences and the lists stored on Windows?
  Web Page format doesn't work for me
  Upgrade to the App Store app?
  List of attachments in the Preview panel
  How do I get a picture to be displayed on the top of the message? YouTube Video
  Recipients are no longer organized alphabetically
  I would like to know if MaxBulk Mailer can personalize emails?
  Chinese characters and trial version footer issues
  How can I upgrade the App Store version to last available on maxprog?
  Unified Email server
  Desactivar notificaciones del plan de actualización
  It takes forever to import my email list into the software
  The iCash Currency Manager doesn't update anymore
  I'm receiving lots of 'Undelivered Mail Returned to Sender' bounces
  Connection problem with Apple iCloud server Screenshot
  Free upgrade, or not free?
  I can't send a PDF attached to my message when it contains pictures
  Can I download files with sequential numbers in their name? Screenshot
  Problem applying styles to a conditional statement result
  Any MaxBulk Mailer tutorial to get started?
  How to upgrade from Standard to Pro Screenshot
  License Key Recovery
  Cannot install the last update
  MaxBulk Mailer sent all the messages to me rather than the recipients
  Erreur d'authentification du serveur Gmail YouTube Video
  Does MaxBulk Mailer come with its own internal SMTP server?
  Pièces jointes
  Stops processing in the middle of the list
  I lost the activation code / license number
  How I can I recover the serial number?
  How I can change the old activation key with the new one?
  Adding Hyperlinks to MaxBulk Mailer messages
  Emails not received despite MaxBulk Mailer delivery confirmation
  Any dedicated bulk mail server I can use with MaxBulk Mailer?
  All transactions are displayed with the same date
  Can I pay with Bitcoins?
  Adding an Unsubscribe link to messages
  Your document is set to ISO-8859-1 but your HTML code use UTF-8 Screenshot
  Problems with importing tab delimited files.
  Updates for AppStore Version
  Editing the Transaction Types list on Windows
  Problème de connexion
  Adding a URL to an image and placing pictures side by side YouTube Video
  How to configure office 365 of microsoft

Generic questions
New paragraph
How do I install Maxprog software on my computer?
macOS
MS Windows
New paragraph
How can I change an application language?
macOS
MS Windows
New paragraph
How to register the software I've just purchased?
macOS
MS Windows
New paragraph
How can I recover the serials I have lost of products I purchased here?
macOS
MS Windows
New paragraph
How can I recover my serial from a registered application?
macOS
MS Windows
New paragraph
How can I find out the product name and version my serial unlocks?
macOS
MS Windows
New paragraph
Where can I read your software License Agreement?
macOS
MS Windows
New paragraph
How to fix software issues (doesn't start, runs slowly, crashes often, ...)
macOS
MS Windows
New paragraph
Double-clicking on my files no longer opens them with the software, why?
macOS
MS Windows
Stan Busk If you want to make the most of the software that you have acquired at Maxprog, do not miss the Stan's Blog. It is a library of Tutorials and Tips covering specific features and tipical problems you may have when using our tools. This page is updated regularly depending on the topics discussed in our public forums and issues reported thru our HelpDesk. If you are interested on what we are currently working on (or want to participate in beta testings) don't miss the Stan's Logbook.
For years, MAX Programming has provided companies around the globe with sophisticated and innovative solutions. Our commitment to quality is not only evident in our products, but also in our people. It is our mission in Professional Support Services to ensure that our products perform to the fullest of their ability in order to meet the business objectives of our customers. We provide the tools and information required for improved productivity. To accomplish this, we offer an array of services including: Technical Support, Education Services and Consulting Services.

Maxprog is part of an internet site network made of desktoolset.com, emaildesignstudio.com, familycash.com, icash.promo, maxbulkmailer.com, maxprog.com, maxprog.net, maxprog.org, maxprog.us, myrecipients.com, newslettercomposer.com, sharedcontents.com, stanbusk.com, stanbusk.pairserver.com, usertools.com.

 !  You can add Anonymous comments! They are moderated though. In order to add a comment without moderation just log in using your Google, Twitter, GitHub, GitLab or Commento login data.




Did you like this post? Share it!



Home Products Downloads News Store Support Forums