FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » split array and string from string (trust me it will make sense when you read)
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: split array and string from string (trust me it will make sense when you read) [message #180791 is a reply to message #180790] Tue, 19 March 2013 04:17 Go to previous messageGo to previous message
cph is currently offline  cph
Messages: 10
Registered: September 2012
Karma:
Junior Member
I know of a way where I can step though looking for each instance of "[" reading between that and the next "=" and that is my key, then read between the "=" and the "]" for the value. Lead each of those sub strings into an array. Then do a str_ireplace to replace [$key=$value] with "". Just curious if there is an easier way.

On Monday, March 18, 2013 9:12:28 PM UTC-7, CloudPress wrote:
> I have a string that consists of several key value pairs such as [key=value], a given key may appear more than once.
>
>
>
> For example a string of:
>
>
>
> "Hello world, [key=value] [key2=value1] This is just a test. [key=value2]"
>
>
>
> I want to do two things, one I want an easier way to view the key value pairs, I am thinking an array
>
>
>
> array ('key' => array ('value', 'value2'), 'key2' => 'value1');
>
>
>
> Secondly I want the key/value pairs removed from the string so I would get the array and a new string that would look like this:
>
>
>
> "Hello world, This is just a test."
>
>
>
> What would be the easiest way to accomplish this?
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Thorny string translation issue.
Next Topic: PDO based Abstraction Layer for MySQL with Caching
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sun Nov 10 15:13:10 GMT 2024

Total time taken to generate the page: 0.05106 seconds