/    Sign up×
Community /Pin to ProfileBookmark

Searching for specific patern

I have a string of text with custom tags ebmedded into:

-Chose country: [COLOR=”RoyalBlue”]<dropdown countries=”usa,uk,canada”>[/COLOR]

What do I need to convert countries entries into html elements like:

<select>
<option value=”usa”>usa</option>
<option value=”uk”>uk</option>
<option value=”uk”>uk</option>

regular expressions,for loop or something else?

Regards.

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@ssystemsNov 24.2009 — Split would be fine unless you have any other requirement. Here's the link. SPLIT
Copy linkTweet thisAlerts:
@BirokratauthorNov 24.2009 — Can you provide a snipet of code?

forgot to tell I need to parse this string "Chose country: <dropdown countries="usa,uk,canada">"
Copy linkTweet thisAlerts:
@BirokratauthorNov 24.2009 — Anyone?
Copy linkTweet thisAlerts:
@NogDogNov 24.2009 — [code=php]
function myReplace($matches)
{
$html = "<select name='" . htmlspecialchars($matches[1]) . "'>n";
$opts = explode(',', $matches[2]);
foreach($opts as $opt)
{
$html .= "<option>$opt</option>n";
}
$html .= "</select>n";
return $html;
}
$regexp = '#<dropdown ([^=]+)=["']([^"']+)["']>#';
$text = '-Chose country: <dropdown countries="usa,uk,canada">';
$text = preg_replace_callback($regexp, 'myReplace', $text);
[/code]
Copy linkTweet thisAlerts:
@BirokratauthorNov 24.2009 — @NogDog you are a genious!
×

Success!

Help @Birokrat 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 5.17,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

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

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...