Jump to content

How would you achieve this?


Jeffro

Recommended Posts

Well first thing that you need to do is to get the location of the ".com" in the string. You would do that like this..

<?php
$pos = strpos($string, '.com', 1);
?>

 

From there you could use the substring function to get the remaining letters like this..

<?php
//right now the value of "$pos" is beginning of the '.com'
//we need to increase it by 5 to adjust for the length of the .com as well as scrapping the 1st letter like you requested
$pos = $pos +5;
$result = substr($string, $pos, 3);
echo $result;
?>

Link to comment
Share on other sites

Thx guys.  I combined both of your solutions to make it work.  Since the first example provided the first 3 characters only and I needed 2, 3, and 4, I used it.. and then used strpos to get what I needed from that. 

 

Many thanks! 

Link to comment
Share on other sites

i misread your post, so if you wanted to use my code i will revise to be exactly what you want, the second third and fourth characters after the .com, im assuming that you do not want the forward slash

preg_match('/\.com\/(.{3})/', $string, $matches);
echo $matches[1];

Link to comment
Share on other sites

i misread your post, so if you wanted to use my code i will revise to be exactly what you want, the second third and fourth characters after the .com, im assuming that you do not want the forward slash

preg_match('/\.com\/(.{3})/', $string, $matches);
echo $matches[1];

 

Cool.. even easier.  Thanks for the help.  Much appreciated!  Works great. 

Link to comment
Share on other sites

i misread your post, so if you wanted to use my code i will revise to be exactly what you want, the second third and fourth characters after the .com, im assuming that you do not want the forward slash

preg_match('/\.com\/(.{3})/', $string, $matches);
echo $matches[1];

 

Cool.. even easier.  Thanks for the help.  Much appreciated!  Works great.

no problem at all, glad it worked for you

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.