/    Sign up×
Community /Pin to ProfileBookmark

pattern question

this is me with usssual patern question … ehh i should het that pattersn book.
So i wanted to backup my phone address book but it is not in a vCard format so I wanna convert file to a vCard… oroginal file is Some junk + vCard, so I jut want to strip the junk off… can some one help me out with patern ofr preg_math

here is my file content:

[code=php]
11110010001000000000L[][][][][][][][]BEGIN:VCARD
VERSION:2.1
N:Check Bill Balance;;;;
TEL;CELL:*225#
TEL;HOME:
TEL;WORK:
TEL;FAX:
TEL:
NOTE:
EMAIL:
END:VCARD
[][][][][][][][][]11110010001000000000L[][][][][][][][]BEGIN:VCARD
[/code]

[] = are some boxes that probably mean simething in hex but they can not be copied. Anyway I hope I would be able to open file on the web as text and then just strip everything.

Here is logic that I would need:

delete all charakters betweenBEGIN:VCARD and BEGIN:VCARD (but not in reverse) In another words we have some unknown code and then we have our vCard, we wanht to see the vCrd declaration and dont delete it (unfortunantly there is not even a space between those charakters and the beginning ov vCard)

Hope you can help ?

THanks!

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@stephan_gerlachFeb 19.2009 — I like to keep it simple so I would do it this way

this assumes that all code is held in the variable $data


[code=php]

$vcard = array();

$parts = explode('BEGIN:VCARD',$data);

foreach ($parts as $part) {

if(strstr($part,'END:VCARD')) {
$parts2 = explode('END:VCARD',$part);
array_push($vcard,'BEGIN:VCARD'.$parts2[0].'END:VCARD');
}

}

[/code]


Not entirely sure if this will work but sure you can work with it.
Copy linkTweet thisAlerts:
@alexusauthorFeb 19.2009 — thanks a lot!

worked perfectly?
×

Success!

Help @alexus 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.16,
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: @nearjob,
tipped: article
amount: 1000 SATS,

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

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