skip to main | skip to sidebar

shanmugarajan

php,mysql,ajax hints

Friday, April 4, 2008

php Substring Examples

Use substr( ) to select your substrings:

$substring = substr($string,$start,$length);
$username = substr($_REQUEST['username'],0,8);

1.2.2. Discussion

If $start and $length are positive, substr( ) returns $length characters in the string, starting at $start. The first character in the string is at position 0:

print substr('watch out for that tree',6,5);
out f

If you leave out $length, substr( ) returns the string from $start to the end of the original string:

print substr('watch out for that tree',17);
t tree

If $start plus $length goes past the end of the string, substr( ) returns all of the string from $start forward:

print substr('watch out for that tree',20,5);
ree

If $start is negative, substr( ) counts back from the end of the string to determine where your substring starts:

print substr('watch out for that tree',-6);
print substr('watch out for that tree',-17,5);
t tree
out f

If $length is negative, substr( ) counts back from the end of the string to determine where your substring ends:

print substr('watch out for that tree',15,-2);
print substr('watch out for that tree',-4,-1);
hat tr
tre
Posted by shanmuga at 3:02 AM

No comments:

Post a Comment

Newer Post Older Post Home
Subscribe to: Post Comments (Atom)

Join with me

Snap Shots

Get Free Shots from Snap.com

Labels

  • General (12)
  • php (11)
  • tamil jokes (10)
  • tamil (8)
  • php5 (7)
  • Google Chrome (6)
  • php functions (5)
  • JavaScript (4)
  • Tamil Kadi jokes (3)
  • htaccess (3)
  • html (3)
  • jokes (3)
  • linux (3)
  • .htaccess (2)
  • CSS (2)
  • Mysql (2)
  • Passport status enquiry (2)
  • Tamil movie (2)
  • apache (2)
  • browser (2)
  • fun (2)
  • indian passport status (2)
  • madurai passport status (2)
  • Bangalore PHP Users MeetUp (1)
  • Cricket (1)
  • ELECTRONIC CIGARETTE (1)
  • Enthiran (1)
  • Epassport (1)
  • Extract rar files in Linux (1)
  • Genereal (1)
  • Google API (1)
  • Google Chrome OS (1)
  • Google Maps hints (1)
  • Google OS (1)
  • Google adsense tricks (1)
  • Greetings (1)
  • IPL 2009 (1)
  • IPL Indian Premier League - Watch Online (1)
  • Java plugin for Google Chrome (1)
  • Linux / Unix Command: unzip (1)
  • Load testing tool (1)
  • Opensta (1)
  • PHP professionals (1)
  • POP ALBUM (1)
  • Regular Expression (1)
  • SONGS (1)
  • Season Greetings (1)
  • Success Baby (1)
  • Sun Tv new Comedy Channel (1)
  • TV SHOWS DOWNLOAD (1)
  • Testing Tool (1)
  • TraceMonkey (1)
  • Trends Search (1)
  • ZCE (1)
  • adsense (1)
  • blog ramnadinfo (1)
  • chrome (1)
  • create cv (1)
  • database migration (1)
  • demo OS (1)
  • dynamic table column display (1)
  • earn money (1)
  • ebook (1)
  • free performance testing tool (1)
  • freeware testing tools (1)
  • google Maps (1)
  • health tips (1)
  • image convertion (1)
  • javasript (1)
  • jquery (1)
  • kanthasamy songs download (1)
  • kavithai (1)
  • mozilla browser vs IE (1)
  • patern matching (1)
  • php security (1)
  • political updates (1)
  • short cuts for mozila (1)
  • special charater issue (1)
  • sql (1)
  • tamil sms jokes (1)
  • ten video sharing site (1)
  • video sites (1)
  • virtual host (1)
  • word to pdf (1)
  • yoga (1)
  • zend certified engineer exam (1)

Search on this site

Blog Archive

  • ►  2010 (1)
    • ►  June (1)
  • ►  2009 (33)
    • ►  November (2)
    • ►  October (1)
    • ►  September (2)
    • ►  July (5)
    • ►  June (3)
    • ►  May (4)
    • ►  April (3)
    • ►  February (3)
    • ►  January (10)
  • ▼  2008 (254)
    • ►  December (2)
    • ►  November (3)
    • ►  October (16)
    • ►  September (37)
    • ►  August (14)
    • ►  July (26)
    • ►  June (4)
    • ►  May (37)
    • ▼  April (46)
      • "Exception thrown and not caught" error On IE
      • "Exception thrown and not caught" error On IE
      • Api Vtiger
      • Google Latest SEO Issues
      • Some examples on how to use call-by-reference in PHP
      • mysql query show tables with like and where
      • Php swap the two variables by reference
      • Display the dyanamic column in php/mysql
      • How to remove/delete the duplicate entry in mysql
      • What are the advantages of stored procedures, trig...
      • perl examples
      • Some interesting Bugs in php
      • pregquote
      • Smarty sites
      • orcale
      • Connecting to a database Simple query
      • Simple Perl Script
      • perl books
      • how to create the view in Mysql
      • Free html/css/wordpress template
      • Adobe AIR brings the Web to the desktop
      • Moving to CSS-based layouts with the YUI Library
      • Fwd: What is cross-site scripting?
      • use curl function instead of file_get_contents
      • How to change PHP parameters when you don't have a...
      • How do I change the PHP Max Upload file size? (.ht...
      • jquery lightbox script
      • Create a thumbnail in php
      • simple xml
      • Shell script dir
      • batch file with php
      • Manual installation in linux/unbntu DEB,RPM FILES
      • ping server
      • Alexa Ranks Very simple script
      • php get the alexa ranking script
      • Linux grep
      • grep example linux with php
      • ugadi greetings
      • php online Examination
      • Php imap email function
      • php Substring Examples
      • Php Questions
      • Read Gmail inbox as a rss feed
      • Jquery Table fileder
      • how to fix IE "Page Has Expired error"
      • Linux Commands
    • ►  March (25)
    • ►  February (33)
    • ►  January (11)
  • ►  2007 (12)
    • ►  December (5)
    • ►  November (6)
    • ►  October (1)

Visit Count

About Me

My photo
shanmuga
View my complete profile