Skip to content

emka.web.id

menulis pengetahuan – merekam peradaban

Menu
  • Home
  • Tutorial
  • Makalah
  • Ke-NU-an
  • Kabar
  • 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

  • Cara Menggunakan Stellarium Web
  • Cara Menghapus Data KTP Pribadi di Pinjol yang Belum Lunas
  • Cara Mengganti Nomor TikTok yang Tidak Aktif atau Hilang Tanpa Verifikasi
  • Cara Menggunakan BCA PayLater Terbaru 2025
  • Cara Mendapatkan IMPoint Indosat IM3 Ooredoo Gratis via MyIM3
  • Apa Arti TikTok ‘Shared With You’?
  • Cara Menghapus Data KTP di Pinjol: Panduan Lengkap
  • Cara Download WhatsApp GB Terbaru 2025 – Fitur Lengkap & Aman
  • Review WhatsApp Beta: Apakah Aman? Cara Instal dan Cara Keluar
  • Bebong: Makna, Asal Usul, dan Penggunaan dalam Bahasa Indonesia
  • Spinjam dan Spaylater: Apa yang Terjadi Jika Terlambat Membayar dan Bisakah Meminjam Lagi?
  • Cara Download dan Menonton Dood Stream Tanpa Iklan – Doods Pro
  • Cara Menghentikan dan Mengatasi Pinjol Ilegal
  • Kode Bank BRI untuk Transfer ke PayPal
  • Cara Menyadap WhatsApp Tanpa Aplikasi dan Kode QR
  • Apa yang Terjadi Jika Telat Bayar Shopee PayLater?
  • Telat Bayar Listrik 1 Hari: Apa yang Terjadi?
  • Cara Mengunduh Foto Profil WhatsApp Teman di Android, iPhone, dan PC/Mac
  • Rekomendasi Aplikasi Edit Foto Ringan Terbaik untuk PC Windows dan macOS
  • Cara Membeli Diamond Mobile Legends Menggunakan Pulsa Telkomsel
  • Tutorial Menggunakan Aplikasi Dana: Cara Top Up Dana dengan Mudah, Cepat, dan Murah untuk Pemula
  • Website Konverter YouTube ke MP3 Terbaik 2025
  • Cara Mengatasi Otorisasi Kadaluarsa Higgs Domino Tanpa Login Facebook
  • Tips Main E-Football 2024: Strategi Pemilihan Tim dan Pemain Terbaik
  • DramaQ: Situs Nonton Drakor Sub Indo Terbaru dan Lengkap
  • IGLookup: Cara Download APK dan Informasi Lengkap
  • Cara Daftar DrakorID? Apakah DrakorID Streaming Penipu/Ilegal?
  • Cara Login, Register, dan Transfer Data MyKONAMI
  • Website PT Melia Sehat Sejahtera Apakah Penipuan?
  • Alternatif APK Bling2: Alternatif Stylish untuk Ekspresi Diri
  • Cara Menggunakan Stellarium Web
  • Cara Menghapus Data KTP Pribadi di Pinjol yang Belum Lunas
  • Cara Mengganti Nomor TikTok yang Tidak Aktif atau Hilang Tanpa Verifikasi

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