Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Senior Coder
    Join Date
    Jun 2008
    Location
    Cornwall
    Posts
    2,097
    Thanks
    297
    Thanked 12 Times in 12 Posts

    creating an array of a string but changing & for and and visa versa?

    Hi All,

    ok i have a wierd request

    i am wondering if it is possible to create an array from a string where but each array value is a new possibility for that phrase.

    for example if the phrase was
    i like php and javascript

    could i some how add that line to an array and all other possibe ways of writing that line

    e.g
    array[1] => i like php and javascript
    array[2] => i like php & javascript

    im sure there are other possibilities?

    but i suppose what im looking for is a string replace function? which then adds the new value to an array?

    is this possible
    many thanks
    Luke

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Yeah:
    PHP Code:
    function andToAmpersand($item)
    {
        return 
    str_replace(' and '' & '$item);
    }

    $aPhrases = array(
        
    'I like PHP and Javascript',
    )

    $aSecondPhrases array_map('andToAmpersand'$aPhrases);
    $aComplete array_merge($aPhrases$aSecondPhrases); 
    That what you're looking for?
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • Users who have thanked Fou-Lu for this post:

    LJackson (09-02-2009)

  • #3
    Senior Coder
    Join Date
    Jun 2008
    Location
    Cornwall
    Posts
    2,097
    Thanks
    297
    Thanked 12 Times in 12 Posts
    wow that is great thanks mate,

    im having a brain fart at the mo and my mind has gone blank
    are there any other symbols which are commonly used to abbreviate text, which i can do the same for?

    thanks for your help mate...
    Luke

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Yeah.
    Actually, it says in the str_replace api that these parameters can all be an array. So you could write one array of $search, one array of $replace, and take an array for its $subject. This should then return an array as well, so you won't need to use an array_map at all. You can just use the str_replace, than merge it with the original.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #5
    Senior Coder
    Join Date
    Jun 2008
    Location
    Cornwall
    Posts
    2,097
    Thanks
    297
    Thanked 12 Times in 12 Posts
    ah right cool, i will look into it. thanks

    Luke

  • #6
    Regular Coder mOrloff's Avatar
    Join Date
    Nov 2008
    Location
    The Great Pacific NW, USA
    Posts
    422
    Thanks
    8
    Thanked 6 Times in 6 Posts
    Quote Originally Posted by LJackson View Post
    ...are there any other symbols which are commonly used to abbreviate text...?


    None come to mind for commonly used abbreviations, but one rarely used may be "=" for "is", or something along those lines.

    ~ Mo

  • #7
    Senior Coder
    Join Date
    Jun 2008
    Location
    Cornwall
    Posts
    2,097
    Thanks
    297
    Thanked 12 Times in 12 Posts
    cheers Mo, i couldn't think of any more commonly used one either, maybe there arnt any others?

    thanks
    Luke


  •  

    Posting Permissions

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