SlideShare ist ein Scribd-Unternehmen logo
1 von 15
Downloaden Sie, um offline zu lesen
axelerant.com 1
PHP 8: String Helpers
@kunalkursija https://www.drupalcampatlanta.com/
DrupalCamp Atlanta
axelerant.com 2
Hello!
I am Kunal Kursija
• Mumbai, Indi
a

• Drupal Staff Engineer - @axeleran
t

• Twitter: @kunalkursij
a

• Drupal: https://www.drupal.org/u/kunalkursija
• LinkedIn: https://www.linkedin.com/in/kunalkursija/
@kunalkursija https://www.drupalcampatlanta.com/
axelerant.com 3
Let’s address the ElePHPant in this room
@kunalkursija https://www.drupalcampatlanta.com/
axelerant.com 4
Strings
@kunalkursija https://www.drupalcampatlanta.com/
axelerant.com 5
@kunalkursija https://www.drupalcampatlanta.com/
String Operations
∞
axelerant.com 6
Problems start with a google search…
@kunalkursija https://www.drupalcampatlanta.com/
axelerant.com 7
Solutions create confusion
@kunalkursija https://www.drupalcampatlanta.com/
Solution
Solution Solution
Solution
axelerant.com 8
PHP check If a string contains…
@kunalkursija https://www.drupalcampatlanta.com/
if (strpos('DCATL is awesome', 'awesome') !== false)
{

echo 'Line ' . __LINE__ . ': ' . "Jackpot! n"
;

}
if (substr_count('DCATL is awesome', 'awesome') > 0)
{

echo 'Line ' . __LINE__ . ': ' . "Jackpot! n"
;

}
if (preg_match('/bawesomeb/', 'DCATL is awesome'))
{

echo 'Line ' . __LINE__ . ': ' . "Jackpot! n"
;

}
if (strstr('DCATL is awesome', 'awesome'))
{

echo 'Line ' . __LINE__ . ': ' . "Jackpot! n"
;

}
if (count(explode('awesome', 'DCATL is awesome')) > 1)
{

echo 'Line ' . __LINE__ . ': ' . "Jackpot! n"
;

}
if (in_array('awesome', explode(' ', 'DCATL is awesome')) )
{

echo 'Line ' . __LINE__ . ': ' . "Jackpot! n"
;

}
axelerant.com 9
PHP check If a string starts with…
@kunalkursija https://www.drupalcampatlanta.com/
if (strpos('DCATL is awesome', 'DCATL') === 0)
{

echo 'Line ' . __LINE__ . ': ' . "Jackpot! n"
;

}
if (substr( 'DCATL is awesome', 0, 5 ) === "DCATL")
{

echo 'Line ' . __LINE__ . ': ' . "Jackpot! n"
;

}
if (substr('DCATL is awesome', 0, strlen('DCATL')) === 'DCATL')
{

echo 'Line ' . __LINE__ . ': ' . "Jackpot! n"
;

}
if (preg_match('#^DCATL#', 'DCATL is awesome') === 1)
{

echo 'Line ' . __LINE__ . ': ' . "Jackpot! n"
;

}
if (strncmp('DCATL is awesome', 'DCATL', 5) === 0)
{

echo 'Line ' . __LINE__ . ': ' . "Jackpot! n"
;

}
axelerant.com 10
PHP check If a string ends with…
@kunalkursija https://www.drupalcampatlanta.com/
if (substr('DCATL is awesome', -7) === 'awesome')
{

echo 'Line ' . __LINE__ . ': ' . "Jackpot! n"
;

}
if (preg_match('/awesome$/', 'DCATL is awesome'))
{

echo 'Line ' . __LINE__ . ': ' . "Jackpot! n"
;

}
$search = explode('awesome', 'DCATL is awesome')
;

if (end($search) == '')
{

echo 'Line ' . __LINE__ . ': ' . "Jackpot! n"
;

}
if (strpos(strrev('DCATL is awesome'), strrev('awesome')) === 0)
{

echo 'Line ' . __LINE__ . ': ' . "Jackpot! n"
;

}
if (!in_array('awesome', explode('awesome', 'DCATL is awesome')) )
{

echo 'Line ' . __LINE__ . ': ' . "Jackpot! n"
;

}
if (strrpos('DCATL is awesome', 'awesome') === strlen('DCATL is awesome') - strlen('awesome'))
{

echo 'Line ' . __LINE__ . ': ' . "Jackpot! n"
;

}
if (substr_compare('DCATL is awesome', 'awesome', -strlen('awesome')) === 0)
{

echo 'Line ' . __LINE__ . ': ' . "Jackpot! n"
;

}
axelerant.com 11
PHP 8: String Helpers
@kunalkursija
To rescue
https://www.drupalcampatlanta.com/
axelerant.com 12
@kunalkursija
Demo
https://www.drupalcampatlanta.com/
axelerant.com 13
Can we get PHP 8 features on Drupal application without having PHP 8?
@kunalkursija
https://github.com/symfony/polyfill-php80
https://www.drupalcampatlanta.com/
axelerant.com 14
Questions?
@kunalkursija https://www.drupalcampatlanta.com/
axelerant.com 15
Thank You!
@kunalkursija
DrupalCamp Atlanta
https://www.drupalcampatlanta.com/

Weitere ähnliche Inhalte

Ähnlich wie Php 8: String Helpers

Lucandra
LucandraLucandra
Lucandraotisg
 
Spick and span php unit tests using data providers
Spick and span php unit tests using data providersSpick and span php unit tests using data providers
Spick and span php unit tests using data providersKunal Kursija
 
Top 10 php classic traps confoo
Top 10 php classic traps confooTop 10 php classic traps confoo
Top 10 php classic traps confooDamien Seguy
 
The top 5 JavaScript issues in all our codebases
The top 5 JavaScript issues in all our codebasesThe top 5 JavaScript issues in all our codebases
The top 5 JavaScript issues in all our codebasesPhil Nash
 
How Xslate Works
How Xslate WorksHow Xslate Works
How Xslate WorksGoro Fuji
 
Writing Friendly libraries for CodeIgniter
Writing Friendly libraries for CodeIgniterWriting Friendly libraries for CodeIgniter
Writing Friendly libraries for CodeIgniterCodeIgniter Conference
 
Web Scraper Shibuya.pm tech talk #8
Web Scraper Shibuya.pm tech talk #8Web Scraper Shibuya.pm tech talk #8
Web Scraper Shibuya.pm tech talk #8Tatsuhiko Miyagawa
 
Rapid Prototyping with Solr
Rapid Prototyping with SolrRapid Prototyping with Solr
Rapid Prototyping with SolrErik Hatcher
 
Assignment 13assg-13.cppAssignment 13assg-13.cpp   @auth.docx
Assignment 13assg-13.cppAssignment 13assg-13.cpp   @auth.docxAssignment 13assg-13.cppAssignment 13assg-13.cpp   @auth.docx
Assignment 13assg-13.cppAssignment 13assg-13.cpp   @auth.docxbraycarissa250
 
Apache spark as a gateway drug to FP concepts taught and broken - Curry On 2018
Apache spark as a gateway drug to FP concepts taught and broken - Curry On 2018Apache spark as a gateway drug to FP concepts taught and broken - Curry On 2018
Apache spark as a gateway drug to FP concepts taught and broken - Curry On 2018Holden Karau
 
Rocky Nevin's presentation at eComm 2008
Rocky Nevin's presentation at eComm 2008Rocky Nevin's presentation at eComm 2008
Rocky Nevin's presentation at eComm 2008eComm2008
 
XML and Web Services with PHP5 and PEAR
XML and Web Services with PHP5 and PEARXML and Web Services with PHP5 and PEAR
XML and Web Services with PHP5 and PEARStephan Schmidt
 
What's new in Perl 5.10?
What's new in Perl 5.10?What's new in Perl 5.10?
What's new in Perl 5.10?acme
 
Best practices in museum search
 Best practices in museum search Best practices in museum search
Best practices in museum searchNate Solas
 
An Introduction to CSS Preprocessors
An Introduction to CSS PreprocessorsAn Introduction to CSS Preprocessors
An Introduction to CSS PreprocessorsMiloš Sutanovac
 

Ähnlich wie Php 8: String Helpers (20)

Bioinformatica p4-io
Bioinformatica p4-ioBioinformatica p4-io
Bioinformatica p4-io
 
Easy R
Easy REasy R
Easy R
 
Lucandra
LucandraLucandra
Lucandra
 
Download It
Download ItDownload It
Download It
 
Spick and span php unit tests using data providers
Spick and span php unit tests using data providersSpick and span php unit tests using data providers
Spick and span php unit tests using data providers
 
Top 10 php classic traps confoo
Top 10 php classic traps confooTop 10 php classic traps confoo
Top 10 php classic traps confoo
 
The top 5 JavaScript issues in all our codebases
The top 5 JavaScript issues in all our codebasesThe top 5 JavaScript issues in all our codebases
The top 5 JavaScript issues in all our codebases
 
How Xslate Works
How Xslate WorksHow Xslate Works
How Xslate Works
 
Writing Friendly libraries for CodeIgniter
Writing Friendly libraries for CodeIgniterWriting Friendly libraries for CodeIgniter
Writing Friendly libraries for CodeIgniter
 
Web Scraper Shibuya.pm tech talk #8
Web Scraper Shibuya.pm tech talk #8Web Scraper Shibuya.pm tech talk #8
Web Scraper Shibuya.pm tech talk #8
 
Rapid Prototyping with Solr
Rapid Prototyping with SolrRapid Prototyping with Solr
Rapid Prototyping with Solr
 
Jquery 1
Jquery 1Jquery 1
Jquery 1
 
Assignment 13assg-13.cppAssignment 13assg-13.cpp   @auth.docx
Assignment 13assg-13.cppAssignment 13assg-13.cpp   @auth.docxAssignment 13assg-13.cppAssignment 13assg-13.cpp   @auth.docx
Assignment 13assg-13.cppAssignment 13assg-13.cpp   @auth.docx
 
Apache spark as a gateway drug to FP concepts taught and broken - Curry On 2018
Apache spark as a gateway drug to FP concepts taught and broken - Curry On 2018Apache spark as a gateway drug to FP concepts taught and broken - Curry On 2018
Apache spark as a gateway drug to FP concepts taught and broken - Curry On 2018
 
Php 2
Php 2Php 2
Php 2
 
Rocky Nevin's presentation at eComm 2008
Rocky Nevin's presentation at eComm 2008Rocky Nevin's presentation at eComm 2008
Rocky Nevin's presentation at eComm 2008
 
XML and Web Services with PHP5 and PEAR
XML and Web Services with PHP5 and PEARXML and Web Services with PHP5 and PEAR
XML and Web Services with PHP5 and PEAR
 
What's new in Perl 5.10?
What's new in Perl 5.10?What's new in Perl 5.10?
What's new in Perl 5.10?
 
Best practices in museum search
 Best practices in museum search Best practices in museum search
Best practices in museum search
 
An Introduction to CSS Preprocessors
An Introduction to CSS PreprocessorsAn Introduction to CSS Preprocessors
An Introduction to CSS Preprocessors
 

Mehr von Kunal Kursija

Decoupling entity validations from entity forms
Decoupling entity validations from entity formsDecoupling entity validations from entity forms
Decoupling entity validations from entity formsKunal Kursija
 
Decoupling entity-validations from entity-forms
Decoupling entity-validations from entity-formsDecoupling entity-validations from entity-forms
Decoupling entity-validations from entity-formsKunal Kursija
 
Modern java script features
Modern java script featuresModern java script features
Modern java script featuresKunal Kursija
 
Modern JavaScript features
Modern JavaScript featuresModern JavaScript features
Modern JavaScript featuresKunal Kursija
 
Symfony and Drupal 8
Symfony and Drupal 8Symfony and Drupal 8
Symfony and Drupal 8Kunal Kursija
 
DrupalCamp Mumbai 2017: Drupal 8 and Commerce 2.x
DrupalCamp Mumbai 2017: Drupal 8 and Commerce 2.xDrupalCamp Mumbai 2017: Drupal 8 and Commerce 2.x
DrupalCamp Mumbai 2017: Drupal 8 and Commerce 2.xKunal Kursija
 

Mehr von Kunal Kursija (6)

Decoupling entity validations from entity forms
Decoupling entity validations from entity formsDecoupling entity validations from entity forms
Decoupling entity validations from entity forms
 
Decoupling entity-validations from entity-forms
Decoupling entity-validations from entity-formsDecoupling entity-validations from entity-forms
Decoupling entity-validations from entity-forms
 
Modern java script features
Modern java script featuresModern java script features
Modern java script features
 
Modern JavaScript features
Modern JavaScript featuresModern JavaScript features
Modern JavaScript features
 
Symfony and Drupal 8
Symfony and Drupal 8Symfony and Drupal 8
Symfony and Drupal 8
 
DrupalCamp Mumbai 2017: Drupal 8 and Commerce 2.x
DrupalCamp Mumbai 2017: Drupal 8 and Commerce 2.xDrupalCamp Mumbai 2017: Drupal 8 and Commerce 2.x
DrupalCamp Mumbai 2017: Drupal 8 and Commerce 2.x
 

Kürzlich hochgeladen

Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024SynarionITSolutions
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024The Digital Insurer
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 

Kürzlich hochgeladen (20)

Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 

Php 8: String Helpers

  • 1. axelerant.com 1 PHP 8: String Helpers @kunalkursija https://www.drupalcampatlanta.com/ DrupalCamp Atlanta
  • 2. axelerant.com 2 Hello! I am Kunal Kursija • Mumbai, Indi a • Drupal Staff Engineer - @axeleran t • Twitter: @kunalkursij a • Drupal: https://www.drupal.org/u/kunalkursija • LinkedIn: https://www.linkedin.com/in/kunalkursija/ @kunalkursija https://www.drupalcampatlanta.com/
  • 3. axelerant.com 3 Let’s address the ElePHPant in this room @kunalkursija https://www.drupalcampatlanta.com/
  • 6. axelerant.com 6 Problems start with a google search… @kunalkursija https://www.drupalcampatlanta.com/
  • 7. axelerant.com 7 Solutions create confusion @kunalkursija https://www.drupalcampatlanta.com/ Solution Solution Solution Solution
  • 8. axelerant.com 8 PHP check If a string contains… @kunalkursija https://www.drupalcampatlanta.com/ if (strpos('DCATL is awesome', 'awesome') !== false) { echo 'Line ' . __LINE__ . ': ' . "Jackpot! n" ; } if (substr_count('DCATL is awesome', 'awesome') > 0) { echo 'Line ' . __LINE__ . ': ' . "Jackpot! n" ; } if (preg_match('/bawesomeb/', 'DCATL is awesome')) { echo 'Line ' . __LINE__ . ': ' . "Jackpot! n" ; } if (strstr('DCATL is awesome', 'awesome')) { echo 'Line ' . __LINE__ . ': ' . "Jackpot! n" ; } if (count(explode('awesome', 'DCATL is awesome')) > 1) { echo 'Line ' . __LINE__ . ': ' . "Jackpot! n" ; } if (in_array('awesome', explode(' ', 'DCATL is awesome')) ) { echo 'Line ' . __LINE__ . ': ' . "Jackpot! n" ; }
  • 9. axelerant.com 9 PHP check If a string starts with… @kunalkursija https://www.drupalcampatlanta.com/ if (strpos('DCATL is awesome', 'DCATL') === 0) { echo 'Line ' . __LINE__ . ': ' . "Jackpot! n" ; } if (substr( 'DCATL is awesome', 0, 5 ) === "DCATL") { echo 'Line ' . __LINE__ . ': ' . "Jackpot! n" ; } if (substr('DCATL is awesome', 0, strlen('DCATL')) === 'DCATL') { echo 'Line ' . __LINE__ . ': ' . "Jackpot! n" ; } if (preg_match('#^DCATL#', 'DCATL is awesome') === 1) { echo 'Line ' . __LINE__ . ': ' . "Jackpot! n" ; } if (strncmp('DCATL is awesome', 'DCATL', 5) === 0) { echo 'Line ' . __LINE__ . ': ' . "Jackpot! n" ; }
  • 10. axelerant.com 10 PHP check If a string ends with… @kunalkursija https://www.drupalcampatlanta.com/ if (substr('DCATL is awesome', -7) === 'awesome') { echo 'Line ' . __LINE__ . ': ' . "Jackpot! n" ; } if (preg_match('/awesome$/', 'DCATL is awesome')) { echo 'Line ' . __LINE__ . ': ' . "Jackpot! n" ; } $search = explode('awesome', 'DCATL is awesome') ; if (end($search) == '') { echo 'Line ' . __LINE__ . ': ' . "Jackpot! n" ; } if (strpos(strrev('DCATL is awesome'), strrev('awesome')) === 0) { echo 'Line ' . __LINE__ . ': ' . "Jackpot! n" ; } if (!in_array('awesome', explode('awesome', 'DCATL is awesome')) ) { echo 'Line ' . __LINE__ . ': ' . "Jackpot! n" ; } if (strrpos('DCATL is awesome', 'awesome') === strlen('DCATL is awesome') - strlen('awesome')) { echo 'Line ' . __LINE__ . ': ' . "Jackpot! n" ; } if (substr_compare('DCATL is awesome', 'awesome', -strlen('awesome')) === 0) { echo 'Line ' . __LINE__ . ': ' . "Jackpot! n" ; }
  • 11. axelerant.com 11 PHP 8: String Helpers @kunalkursija To rescue https://www.drupalcampatlanta.com/
  • 13. axelerant.com 13 Can we get PHP 8 features on Drupal application without having PHP 8? @kunalkursija https://github.com/symfony/polyfill-php80 https://www.drupalcampatlanta.com/
  • 15. axelerant.com 15 Thank You! @kunalkursija DrupalCamp Atlanta https://www.drupalcampatlanta.com/