Skip to content

emka.web.id

menulis pengetahuan – merekam peradaban

Menu
  • Home
  • Tutorial
  • Search
Menu

PHP Cookbook: Accessing Substrings

Posted on December 11, 2011

Problem
You want to know if a string contains a particular substring. For example, you want to find out if an email address contains a @.

Solution
Use strpos()

[sourcecode language=”php”]
<?php
if (strpos($_POST[’email’], ‘@’) === false) {
print ‘There was no @ in the e-mail address!’;
}
?>
[/sourcecode]

Discussion
The return value from strpos( ) is the first position in the string (the “haystack”) at which the substring (the “needle”) was found. If the needle wasn’t found at all in the haystack, strpos( ) returns false. If the needle is at the beginning of the haystack, strpos( ) returns 0, since position 0 represents the beginning of the string. To differentiate between return values of 0 and false, you must use the identity operator (===) or the not–identity operator (!==) instead of regular equals (==) or not-equals (!=). Example 1-8 compares the return value from strpos( ) to false using ===. This test only succeeds if strpos returns false, not if it returns 0 or any other number.

See Also
Documentation on strpos( ) at http://www.php.net/strpos

Terbaru

  • Apakah Jika Ganti Baterai HP, Data akan Hilang?
  • Apa itu Game Sakura School Simulator Solwa?
  • Hasil Benchmark Xiaomi Pad 8 Global Bocor! Siap-siap Masuk Indonesia Nih
  • KAGET! Ressa Rizky Rossano Akui Sudah Nikah & Punya Anak
  • Inilah Kronologi Ledakan Bom Rakitan SMPN 3 Sungai Raya, Kubu Raya Kalbar
  • Cara Mengatasi Error 208 BCA Mobile
  • Hapus Sekarang! Inilah Hornet, App LGBTQ Tembus Indonesia, Hati-hati
  • Berapa Lama Sih Ngecas HP 33 Watt? Ini Dia Penjelasannya!
  • Cara Cek Saldo Hana Bank Lewat SMS
  • Update Sistem Google Februari 2026: Apa yang Baru dan Perlu Kalian Tahu?
  • Membership FF Bulanan & Mingguan: Berapa DM yang Harus Kalian Siapkan?
  • Maksimal Ngecas HP Berapa Kali Sehari? Boleh 2 Kali Nggak, Sih?
  • Cara Mengatasi Error “Try Again, Open in Another App”
  • Sideload Android: Cara Pasang APK Tanpa Google Play Store (Panduan Lengkap 2026)
  • iPhone Jadi Kamera Vintage Modular? Proyek Kickstarter Ini Bikin Kagum!
  • Cara Mengatasi Video Nest Cam Bermasalah dan Video Hilang
  • iTunes Masih Jadi Rajanya Music? Ini Faktanya!
  • Google Home Smart Button Makin Canggih: Kini Otomatisasi Lebih Fleksibel!
  • F1: The Movie Raih Grammy! Tak Terduga, Kalahkan Bintang Country Ternama
  • Blokir Situs Judi Online: Lindungi Diri & Keluarga dari Dampak Negatif
  • Belanda Larang Anak di Bawah 16 Tahun Gunakan Media Sosial: Ini Detailnya!
  • Gemini Live Mendapat Desain Ulang ‘Floating UI’ yang Super Keren!
  • Galaxy S26 Kehilangan Magnet Qi2? Kebocoran Terbaru Bikin Penasaran!
  • DCT Coin: Crypto Legitim atau Penipuan? Bedah Tuntas, Harga & Fakta Penting!
  • Apple Rilis Update Terbaru untuk iOS, macOS, watchOS & Lainnya!
  • Paket Super Seru Telkomsel: Aplikasi Apa Saja yang Bisa Digunakan?
  • Deus Ex: Human Revolution GRATIS di Android! Buruan Download Sebelum Hilang!
  • Apa Bedanya Thigh, Wing, dan Drumstick di McDonald’s? Yuk, Kupas Tuntas!
  • OpenAI Luncurkan Codex App untuk macOS: Kode Jadi Lebih Mudah!
  • Dana Kaget Wealth Plan: Untung atau Mitos? Review Jujur & Cara Daftarnya!
  • How to Run Qwen (14B) on AMD MI200 with vLLM
  • How to Enable New Run Dialog in Windows 11
  • How to Disable AI Features in Firefox 148
  • Git 2.53: What’s New?
  • Linux From Scratch Ditches Old System V init
  • Cara Membuat Podcast dari PDF dengan NotebookLlama dan Groq
  • Tutorial Membuat Sistem Automatic Content Recognition (ACR) untuk Deteksi Logo
  • Apa itu Google Code Wiki?
  • Cara Membuat Agen AI Otomatis untuk Laporan ESG dengan Python dan LangChain
  • Cara Membuat Pipeline RAG dengan Framework AutoRAG
  • Apa itu Spear-Phishing via npm? Ini Pengertian dan Cara Kerjanya yang Makin Licin
  • Apa Itu Predator Spyware? Ini Pengertian dan Kontroversi Penghapusan Sanksinya
  • Mengenal Apa itu TONESHELL: Backdoor Berbahaya dari Kelompok Mustang Panda
  • Siapa itu Kelompok Hacker Silver Fox?
  • Apa itu CVE-2025-52691 SmarterMail? Celah Keamanan Paling Berbahaya Tahun 2025
Beli Morning Star Kursi Gaming/Kantor disini: https://s.shopee.co.id/805iTUOPRV
Beli Pemotong Rumput dengan Baterai IRONHOOF 588V Mesin Potong Rumput 88V disini https://s.shopee.co.id/70DBGTHtuJ

©2026 emka.web.id | Design: Newspaperly WordPress Theme