28, May 2012

a "backwards" strstr() ? - webmaster forum

 
Webdigity webmaster forums
[ 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
Instabuck - The easy way to sell digital products online

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



« on: May 01, 2007, 07: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?


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


It's time to use PHP5!


« Reply #1 on: May 01, 2007, 08:35:48 pm »

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

I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 5799
46391 credits
Members referred : 3



« Reply #2 on: May 01, 2007, 10: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 or twitter

Last blog : Butterfly Marketing 2.0
Where are my glasses?
*
Posts: 21
138 credits
Members referred : 0


« Reply #3 on: Jul 20, 2007, 12: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: 6691
34714 credits
Members referred : 374


It's time to use PHP5!


« Reply #4 on: Jul 20, 2007, 08: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)

I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 5799
46391 credits
Members referred : 3



« Reply #5 on: Jul 20, 2007, 10: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 or twitter

Last blog : Butterfly Marketing 2.0
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....

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?
May 28, 2012, 10:20:47 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!






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