/    Sign up×
Community /Pin to ProfileBookmark

Getting <div> content

I’m new to PHP so I don’t know it’s specific characteristics, what I’m trying to do is get the content in a <div> tag for an RSS feed. here’s what I have so far:

$txt = file_get_contents(‘http://www.mywebsite.com/‘);
preg_match_all (“/<div class=”mainpost”>([^`]*?)</div>/”, $txt, $cont);

which is what is supposed to take the content from <div class=”main”>content</div>, but is giving me nothing.

If I do:
echo sizeof($cont);

it outputs 2. If I say echo $cont[0] . $cont[1]; it outputs ‘ArrayArray’, which I’m assuming means it created a 2d array, but the problem is sizeof($cont[0]) and sizeof($cont[1]) both return 0. I know that it can read the text because if I echo $txt it shows mywebsite.com, so I’m assuming that I have a problem with the regex that I’m using in preg_match_all.

Thanks for the help.

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@MindzaiJul 03.2009 — Your regex is looking for a class of mainpost, not main. Also to debug an array try this:

[code=php]echo sprintf('<pre>&#37;s</pre>', print_r($array, true));[/code]
Copy linkTweet thisAlerts:
@Squibbles1077authorJul 03.2009 — Thanks for the reply,

The mainpost/main thing was a typo when I was typing the lower part of the reply, it isn't mistyped in the code. The test you suggested returns this:


Array

(

[0] => Array

(

)

[1] => Array
(
)


)

From what I understand, $array[1] is supposed to contain the content.

Thanks!
×

Success!

Help @Squibbles1077 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.18,
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,
)...