22, November 2008

a "backwards" strstr() ? - webmaster forum

 
Webdigity webmaster forums
This forum shares its ad revenue with its members!
[ Home | Help | Search | Forum's Shop | Archive | Login | Register | Webmaster Directory ]
Webdigity Webmaster Forums  >  Web Development  >  PhP
Topic: a "backwards" strstr() ?
« previous next »
Pages: [1] Print

Author Topic: a "backwards" strstr() ?  (Read 848 times)
aka J Love
Community Supporter ?
Bill Gates is my home boy
*****
Gender: Male
Posts: 884
1636 credits
Members referred : 4



« on: May 01, 2007, 08:31:10 PM »

i have searched the php manual for a way to do exactly what it shows for strstr() in the php.net example:

Code:
Example 2374. strstr() example

<?php
$email 
'user@example.com';
$domain strstr($email'@');
echo 
$domain// prints @example.com
?>


except that i would want this example to print user@, instead of @example.com, how would this be possible?

Visit through proxy Visit through proxy Visit through proxy

Last blog : phpHaze 1.59.1 in Development
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6440
39464 credits
Members referred : 374


It's time to use PHP5!


« Reply #1 on: May 01, 2007, 09:35:48 PM »

Code:
$str = 'user@example.com';
substr($str, 0, strpos($str, '@')+1);


Last blog : Just a better Internet portal provided by Google
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 8249
42481 credits
Members referred : 3



« Reply #2 on: May 01, 2007, 11:56:48 PM »

I think that could be done with at least 10 different ways. For instance another one could be :

array_shift(explode('@',$email)) . '@';

Trial and Error my two best teachers Cool
Join us @ facebook Visit through proxy or twitter Visit through proxy

Last blog : Free Unlimited Bandwith and disk space to good to be true?
Where are my glasses?
*
Posts: 21
138 credits
Members referred : 0


« Reply #3 on: Jul 20, 2007, 01:51:14 AM »

Here's a function I wrote to get the last position.

      function strLastPos($haystack, $needle)
      {
          $string = strrev($haystack);
          $needle = strrev($needle);
         
          $pos = strpos($string, $needle);
     
      if ($pos === false)
        return false;
             
          $pos = strlen($haystack) - $pos;
         
          return $pos;
      }

You could use substr() to filter the domain out of the e-mail address.
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6440
39464 credits
Members referred : 374


It's time to use PHP5!


« Reply #4 on: Jul 20, 2007, 09:32:27 AM »

As Nick said there are thousand ways to Athene Cheesy (Nick, I guess you like this version much more then the Rome version, hehe)


Last blog : Just a better Internet portal provided by Google
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 8249
42481 credits
Members referred : 3



« Reply #5 on: Jul 20, 2007, 11:17:51 AM »

As Nick said there are thousand ways to Athene Cheesy (Nick, I guess you like this version much more then the Rome version, hehe)

Yeah right Smiley

Trial and Error my two best teachers Cool
Join us @ facebook Visit through proxy or twitter Visit through proxy

Last blog : Free Unlimited Bandwith and disk space to good to be true?
Trackback URI for this entry : http://www.webdigity.com/trackback.php?topic=6493
Tags : strstr php Bookmark this thread : Digg Del.icio.us Dzone more....

Topic sponsors:
Get a permanent link here for $1.99!


Pages: [1] Print 
Webdigity Webmaster Forums  >  Web Development  >  PhP
Topic: a "backwards" strstr() ?
« previous next »
Jump to:
User Area
Welcome, Guest. Please login or register.
Did you miss your activation email?
Nov 22, 2008, 04:20:41 PM





Login with username, password and session length

Donate to our community, and get a permanent link back to your site!

Donate to our community, and get a permanent link back to your site!


Forum Statistics
Total Posts: 37.736
Total Topics: 7.650
Total Members: 4.397
Tutorials : 56
Resources : 143
Designs : 220
Latest Member: Janai

38 Guests, 5 Users online :

11 users online today:



Readers

Web Design Gallery · Whois Lookup · Pagerank · Tag Browsing · Lo-fi version · Syndication · Webmaster forum history · Advertise
Developed by HumanWorks © 2005 - 2008 Webdigity webmaster community · sublime directory
Webdigity Webmaster Forums | Powered by SMF 1.0.12. © 2001-2005, Lewis Media. All Rights Reserved.