Jump to content


Looking for a PHP function


  • Please log in to reply
4 replies to this topic

#1 Guest_Feces lover_*

Guest_Feces lover_*
  • Guests

Posted 01 July 2006 - 12:30 PM

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.

#2 Orio

Orio
  • Staff Alumni
  • Advanced Member
  • 2,491 posts

Posted 01 July 2006 - 12:37 PM

Can you give an example?

Orio.
Think you're smarty?

(Gone until 20 to November)

#3 heckenschutze

heckenschutze
  • Members
  • PipPipPip
  • Advanced Member
  • 257 posts
  • LocationAustralia

Posted 01 July 2006 - 12:59 PM

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

#4 Guest_Feces lover_*

Guest_Feces lover_*
  • Guests

Posted 01 July 2006 - 01:28 PM

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.

#5 Guest_Feces lover_*

Guest_Feces lover_*
  • Guests

Posted 01 July 2006 - 01:55 PM

I figured out a simple way to do it, which makes me feel really stupid:
if (stristr($input, 'my') !== FALSE && stristr($input, 'name') !== FALSE){
$name = substr($input, 10);
$name = trim ($name, '.');
$response = ("Hello $name!");
}





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users