Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Tokenize (split) string
#1
can you give me example on how to use tok
Code:
Copy      Help
_catid
_cat-title
for
str input like this:
Code:
Copy      Help
//from php -> _catid,_cat-title
1,test;2,site;3,quickmacros
pi
#2
What exactly you want to do?
#3
i want to split php return strings into variables.

IntPost phpmysql post return

result:

1,test;2,site;3,quickmacros

Quote:_catid
_cat-title

with
Code:
Copy      Help
,,ARRAY(str) arr
,,int i nt
,,nt = tok(return &arr)
,,for(i 0 nt) out arr[i]

i get
Code:
Copy      Help
1
test
2
site
3
quickmacros
pi
#4
Extract just values that follow the numbers?
#5
Gintaras Wrote:Extract just values that follow the numbers?

in this case yes.
like
out _catname[_catid]
pi
#6
Here better is findrx. All submatches (enclosed substrings) are exctracted to array starting from indice 1 (0 is for whole match).

Code:
Copy      Help
[color=blue]str [/color]s="1,test;2,site;3,quickmacros"
ARRAY([color=blue]str[/color]) a
[color=blue]str [/color]rx="1,(\w+);2,(\w+);3,(\w+)" [color=green];;if values contain only word characters
;str rx="1,(.+);2,(.+);3,(.+)" ;;if values contain any characters except newline[/color]
[color=blue]if[/color]([color=blue]findrx[/color](s rx 0 0 a)<0) [color=blue]ret[/color]

[color=blue]int [/color]i
[color=blue]for [/color]i 1 a.len
,[color=blue]out [/color]a[i]
#7
that doesn't help.

i need to assign both php variables to qm_variables.

str rx="1,(\w+);2,(\w+);3,(\w+)"
findrx(return rx 0 0 temp)

_catid = 1
_catname = test
_catid = 2
_catname = site
_catid = 3
_catname = quickmacros
pi
#8
maybe i should make it bullet proof:

so every pair is

variable_name=value [linebreak]

i mean i can format (str)return in many ways in php.

do you have a suggestion for a quasi standard ?
pi


Forum Jump:


Users browsing this thread: 1 Guest(s)