skip to Main Content

In input form can I use just the last 10 characters when I submit a form?

For example, this link: http://linkwebiste.com/test?x=123456789012 woulc be the value on an input box (like search) and I’ll submit, but I just require 123456789012.

I want the results of input form to be in another page, like <form action="page2.php" method="post">

There are 2 images for example (in photoshop, created by me):

enter image description here

2

Answers


  1. Use substr() with a -Ve number on the 2nd argument.

    $postedString = "http://linkwebiste.com/test?x=1234567890"
    $lastString = substr($postedString, -10);
    echo $lastString; //will result "1234567890"
    
    Login or Signup to reply.
  2. You can use PHP’s substr() method with a negative offset:

    $last11 = substr($mystr, -10);
    

    From the Manual:

    If start is negative, the returned string will start at the start‘th character from the end of string.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search