Jump to content

Archived

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

Guest Feces lover

Looking for a PHP function

Recommended Posts

Guest Feces lover
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.

Share this post


Link to post
Share on other sites
Try using, substr(), spliting off the first part of the string, inserting your part, and then adding on the end, also found with substr().

Share this post


Link to post
Share on other sites
Guest Feces lover
OK, here's an example. I'm making a PHP chatbot

if (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.

Share this post


Link to post
Share on other sites
Guest Feces lover
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]

Share this post


Link to post
Share on other sites

×

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.