Posted By

jlvallelonga on 07/30/09


Tagged

insert php String into another


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

umang_nine


insertString PHP


 / Published in: PHP
 

URL: http://justpushbuttons.com/examples/insert_string_example.php

use this function to insert a string into another string at a certain position. echo insertString("legendary", " wait for it ... ", 5); legen wait for it ... dary

  1. function insertString($toInstInto, $toInst, $position) {
  2. $firstHalf = substr($toInstInto, 0, $position);
  3. $lastHalf = substr($toInstInto, $position);
  4. $newString = $firstHalf . $toInst . $lastHalf;
  5. return $newString;
  6. }

Report this snippet  

You need to login to post a comment.