insertString PHP


/ Published in: PHP
Save to your folder(s)

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


Copy this code and paste it in your HTML
  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. }

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.