/    Sign up×
Community /Pin to ProfileBookmark

””
<?php
$string = ‘url.com/?tbl=links&col=keyword&search=cars&page=1’;
sscanf($string,’tbl=%s,col=%s,search=%s,page=%d’,$tbl,$col,$Search,$page);
echo ‘tbl :’ .$tbl; echo ‘<br>’;
echo ‘col :’ .$col; echo ‘<br>’;
echo ‘search :’ .$Search; echo ‘<br>’;
echo ‘page :’ .$page; echo ‘<br>’;
?>
””

People,
Why sscanf only deal with 2 here %tbl and %col and not the other two ?
I can only see the first two cars echoed. The last two are empty!
Why ?

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@NogDogFeb 07.2021 — Probably because you use commas in your patter string, but there are none in the actual string?

Anyway, I'd just do:
<i>
</i>$string = 'url.com/?tbl=links&amp;col=keyword&amp;search=cars&amp;page=1';
parse_str(parse_url($string, PHP_URL_QUERY), $result);
var_export($result);

Output:
<i>
</i>array (
'tbl' =&gt; 'links',
'col' =&gt; 'keyword',
'search' =&gt; 'cars',
'page' =&gt; '1',
)


PS: Please use this forum's ... tags around your code snippets.
Copy linkTweet thisAlerts:
@developer_webauthorFeb 11.2021 — @NogDog#1627693

Thsnks a lot! Your code will be handy for my projects.

Anyway, so the 4th and 5th not getting scanf cos I using comma and the commas getting counted as different Params' for the scanf ? Ok, so what else should I use then to separate things inside one Param ? The semi colon ?
×

Success!

Help @developer_web spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...