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;
?>

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];

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. 

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.