SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Apr 2012
    Location
    /dev/zero
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to use PHP to match couples of repeated strings / numbers ?

    I have two strings like followings:
    $s1 = "abccddkkxyz";
    $s2 = "12334466987";

    How to recognize ccddkk in $s1 and 334466 in $s2 ?

    Thank you for your helps.

  2. #2
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    As both your starting values are quoted they are treated as strings in this instance.

    Take a look at how strstr() and strpos work.

  3. #3
    SitePoint Mentor bronze trophy
    John_Betong's Avatar
    Join Date
    Aug 2005
    Location
    City of Angels
    Posts
    1,889
    Mentioned
    74 Post(s)
    Tagged
    6 Thread(s)
    Quote Originally Posted by cuahangsimsodep View Post
    I have two strings like followings:
    $s1 = "abccddkkxyz";
    $s2 = "12334466987";

    How to recognize ccddkk in $s1 and 334466 in $s2 ?

    Thank you for your helps.
    What is the source of your two strings? Are they from the results from a database query?

    It may be a co-incidence but both search strings are six characters long and both occur in the source string starting at the second character ( 0 is the first character).

    If on the off-chance the string you are searching always occurs in the same place then you could use the following:

    PHP Code:

      
    echo substr$s126); # ccddkk 

      
    echo substr$s226); #  334466 
    http://php.net/manual/en/function.substr.php
    Learn how to be ready for The New Move to Discourse

    How to make Make Money Now with a *NEW* look

    Be sure to congratulate Wolfshade on earning Member of the Month for August 2014


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
  •