/    Sign up×
Community /Pin to ProfileBookmark

advanced split string by skipping some text

Hi there,

I want to split a string but in a more advanced way…

So what do i want to do?
I want to split ALL the TEXT between “<table>” and “</table>” from the string… so i can edit the remaining text (string/array)…
and then finally past them back together again…

I know i can use ‘explode()’ and ‘implode()’, but as you might understand… when a user defines more than 1 table… i should make an ‘explode()’ and ‘implode()’ sequence… to cover all the text…

[b]Note:[/b]
I KNOW there’s a way to do what i want… but i cant remember what is was… can you??

So basically…
I want to split a string in a way… that ALL the text between a “<table>” and “</table>” are used to split… in a way… that i can paste the splitted items WITH the text between the table-tags back together…

tnx… for reading/helping…

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@pyroSep 04.2003 — Try something like this:

[code=php]<?PHP
$str = "<table><tr><td>Tabular Data</td></tr><tr><td>More Tabular Data</td></tr></table>";

preg_match("/(<table>)(.*)(</table>)/",$str, $matches);
echo $matches[1]; //<table>
echo $matches[2]; //table contents
echo $matches[3]; //</table>

?>[/code]
Copy linkTweet thisAlerts:
@MasterTomauthorSep 04.2003 — but ehm...

WHAT IF... I put more than 1 (!!) tables on the page...

thát was my real problem.. cause then the code should be dinamical... which would mean... a lot of code... i think...

but i hoped that anyone had an easier way...

does anyone?
Copy linkTweet thisAlerts:
@pyroSep 05.2003 — Do you mean nested tables? If so, you shouldn't be using nested tables anyway -- read up on CSS. If you mean more than one table per page, just split it at each table, and then use the code I posted above.
Copy linkTweet thisAlerts:
@Kr_ZSep 05.2003 — If you mean you want to find all the <table></tables>, instead of just the first one use preg_match_all() instead og preg_match().
×

Success!

Help @MasterTom 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.8,
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,
)...