Guest Feces lover Posted July 1, 2006 Share Posted July 1, 2006 Is there any PHP function that can output a string at a given position of another string? I've looked through the PHP Manual and couldn't find it. Quote Link to comment https://forums.phpfreaks.com/topic/13381-looking-for-a-php-function/ Share on other sites More sharing options...
Orio Posted July 1, 2006 Share Posted July 1, 2006 Can you give an example?Orio. Quote Link to comment https://forums.phpfreaks.com/topic/13381-looking-for-a-php-function/#findComment-51675 Share on other sites More sharing options...
heckenschutze Posted July 1, 2006 Share Posted July 1, 2006 Try using, substr(), spliting off the first part of the string, inserting your part, and then adding on the end, also found with substr(). Quote Link to comment https://forums.phpfreaks.com/topic/13381-looking-for-a-php-function/#findComment-51678 Share on other sites More sharing options...
Guest Feces lover Posted July 1, 2006 Share Posted July 1, 2006 OK, here's an example. I'm making a PHP chatbotif (stristr($input, 'my') !== FALSE && stristr($input, 'name') !== FALSE){$name = //function that gets the 4th word of $input goes here$response = ("Hello $name!");And I'll try the substr() suggestion. Quote Link to comment https://forums.phpfreaks.com/topic/13381-looking-for-a-php-function/#findComment-51679 Share on other sites More sharing options...
Guest Feces lover Posted July 1, 2006 Share Posted July 1, 2006 I figured out a simple way to do it, which makes me feel really stupid:[code]if (stristr($input, 'my') !== FALSE && stristr($input, 'name') !== FALSE){$name = substr($input, 10);$name = trim ($name, '.');$response = ("Hello $name!");}[/code] Quote Link to comment https://forums.phpfreaks.com/topic/13381-looking-for-a-php-function/#findComment-51689 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.