SitePoint Sponsor

User Tag List

Results 1 to 11 of 11
  1. #1
    SitePoint Guru johnjohn2's Avatar
    Join Date
    Apr 2004
    Location
    here
    Posts
    746
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    get statement that retrieves only 4 characters from the right

    Does something like this exist to grab only the last 4 characters of a parameter?

    right(($_GET['col33']),4)


    Where the number "123456789" would equal "6789"

  2. #2
    SitePoint Evangelist
    Join Date
    May 2004
    Location
    Germany
    Posts
    550
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    sub_str($_GET['col33'], -14); 
    hth

  3. #3
    SitePoint Wizard
    Join Date
    Mar 2004
    Posts
    1,647
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    wrong...
    PHP Code:
    sub_str($_GET['col33'], -14); 
    right...
    PHP Code:
    substr($_GET["col33"], -4); 
    cheers

  4. #4
    SitePoint Evangelist
    Join Date
    May 2004
    Location
    Germany
    Posts
    550
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    wrong
    PHP Code:
    substr($_GET['col33'], -4); 
    i should test my code when i'm a little bit tipsy

  5. #5
    SitePoint Guru johnjohn2's Avatar
    Join Date
    Apr 2004
    Location
    here
    Posts
    746
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I tried it out but I'm getting this error:
    Parse error: parse error, unexpected T_STRING, expecting T_VARIABLE or '$' in c:\inetpub\wwwroot\test2\411.php on line 36

    I don't see any problem with the code. Is there one? Line 36 is the first instance of the "substr" entry. Here's what surrounds line 36:

    $startRow_Recordset2 = $pageNum_Recordset2 * $maxRows_Recordset2;
    $a1__Recordset2 = '-1';
    if (isset(substr($_GET['col19'], -4))) {
    $a1__Recordset2 = substr($_GET['col19'], -4);

  6. #6
    SitePoint Evangelist
    Join Date
    May 2004
    Location
    Germany
    Posts
    550
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    if (isset(substr($_GET['col19'], -4))) { 
    substr() returns a string, and isset() expects a $variable.

    so if you wan't to check that $_GET['col19'] is set and at least 4 chars long use
    PHP Code:
    if(isset($_GET['col19'] && strlen($_GET['col19']) > 3)
    {
       
    $a1__Recordset2 substr($_GET['col19'], -4);

    hth

    Edit:


    post #300

  7. #7
    SitePoint Wizard
    Join Date
    Mar 2004
    Posts
    1,647
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ?
    PHP Code:
    $startRow_Recordset2 $pageNum_Recordset2 $maxRows_Recordset2;
    $a1__Recordset2 '-1'# why that here???
    if(isset(substr($_GET['col19'], -4))) { 
    $a1__Recordset2 substr($_GET['col19'], -4); # and then here again??? 
    what is that???

    maybe this will help...
    PHP Code:
    if(!empty($_GET["col19"])) {
    $a1__Recordset2 substr($_GET['col19'], -4); 

    cheers

  8. #8
    SitePoint Member ravikiran's Avatar
    Join Date
    Dec 2004
    Location
    hyderabad
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    May be this:

    if(!empty($_GET["col19"],-4))
    {
    $a1__Recordset2 = substr($_GET['col19'], -4);
    }
    Ravi

  9. #9
    SitePoint Wizard
    Join Date
    Mar 2004
    Posts
    1,647
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    how can be if(!empty($_GET["bla"], -4)) ?

    hth
    PHP Code:
    if(strlen($_GET["col19"]) > 4) {
    $a1__Recordset2 substr($_GET['col19'], -4);

    cheers

  10. #10
    SitePoint Guru johnjohn2's Avatar
    Join Date
    Apr 2004
    Location
    here
    Posts
    746
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This bit of code is from dreamweaver mx 2004. I've tested out:
    <?php echo substr($_GET['col19'], -4); ?> on the screen and it gives the correct results. But when I put in dreamweaver's recordset builder and put in :
    substr($_GET['col19'], -4)
    as a "runtime" value in the variables box, this is where it fails.

  11. #11
    SitePoint Member ravikiran's Avatar
    Join Date
    Dec 2004
    Location
    hyderabad
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    May I have the coding ur using in Dreamweaver and in the PHP file.
    Ravi


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •