How do I get the values between two brackets? For example: $var = 'name(bob) | title(bar) | value(5)'; What code would I need to use if I want to get the values 'bob', 'bar', and '5'. I thought I could use strpos() and strstr() to get the values but my code isn't working! Plz Help!!! ~imozeb
<?php $var = 'name(bob) | title(bar) | value(5)'; preg_match_all('~([^ ]*)\(.*\)~U', $var, $values); print_r($values[1]); ?> PHP:
I'm new to regexps. How do you dump the variables into separete containers. For example $name = name value, $title = title value, and $value = value value? And is there anyway I can stop searching for new text after it has found those three values?
Is there anyway I can do it using strpos() because when I changed $var to 'name(bob) | title(bar) | value(5) # QWERTYUIOP{}|":LKJHGFDSAZXCVBNM<>?+_)(*&^%$#@!234567890-=~`' it printed out all that extra text. Is there anyway preg_match_all can work to fix this, mabye like stopping at the third value. Thanks, Danx10!
<?php $var = 'name(bob) | title(bar) | value(5)'; preg_match_all('~([^ ]*)\(.*\)~U', $var, $values); $name = $values[1][0]; $title = $values[1][1]; $value = $values[1][2]; ?> PHP: