Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
This simple array isn't working...
Old 11-22-2009, 08:47 PM This simple array isn't working...
Physicsguy's Avatar
404 - Title not found

Posts: 920
Name: Scott Kaye
Location: Ontario
Trades: 0
Again, I've made a simple code, but for some strange reason, it doesn't work...

Here it is:

PHP Code:
$FindTitles file_get_contents("info.php");
$FoundTitles explode('h1>',$FindTitles);
echo 
"<p>$FoundTitles[1];</p>"
Line 1: Opens the flat file info.php into $FindTitles
Line 2: Explodes $FindTitles into the parts by any h1>, could be <h1> or </h1>, I just need what's between <h1> and </h1>.
Line 3: Since $FoundTitles is an array, we echo the first one (well really the second one), which would be, say, "Info 1 Title". Then if you change it to 2 between the [ ], you get a blank screen (as well as 3, 4, 5...)...

Why? Why doesn't it work?

What I pretty much need is the script to go in and echo everything between any h1>.

Here's my flat file:

Code:
<div class='contentboxtitle' id='Title'><h1>Info 1 Title</h1></div><div class='contentbox'>CONTENT CONTENT CONTENT</div>|

<div class='contentboxtitle' id='Title'><h1>Info 2 Title</h1></div><div class='contentbox'>CONTENT CONTENT CONTENT</div>|

<div class='contentboxtitle' id='Title'><h1>Info 3 Title</h1></div><div class='contentbox'>CONTENT CONTENT CONTENT</div>|
So I'd need the script to echo "Info 1 TitleInfo 2 TitleInfo3 Title". I don't care about spacing, I can figure that out.

But I can't get it... I have no idea, it's bothering me I'm stumped on a 3 line catastrophe...
__________________
Check out my
Please login or register to view this content. Registration is FREE
or my
Please login or register to view this content. Registration is FREE
!

Last edited by Physicsguy; 11-22-2009 at 08:49 PM.. Reason: added stuff
Physicsguy is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 11-22-2009, 09:06 PM Re: This simple array isn't working...
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,918
Name: Keith Marshall
Location: Connecticut
Trades: 0
PHP Code:
$file file_get_contents("info.php");
$FoundTitles = array();
 
foreach (
$file AS $line)
{
  if (
preg_replace('~<h1>(.*)</h1>~i'$line$match)) $FoundTitles[] = $match[1];
}
 
echo 
"<p>{$FoundTitles[1]};</p>"// Would echo <p>Info 2 Title;</p> 
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Old 11-22-2009, 09:09 PM Re: This simple array isn't working...
Physicsguy's Avatar
404 - Title not found

Posts: 920
Name: Scott Kaye
Location: Ontario
Trades: 0
Thank you, that's farther than I've gotten, but I get this Error:

Warning: Invalid argument supplied for foreach()

I don't know, it doesn't like the line with foreach in it.
__________________
Check out my
Please login or register to view this content. Registration is FREE
or my
Please login or register to view this content. Registration is FREE
!
Physicsguy is offline
Reply With Quote
View Public Profile
 
Old 11-22-2009, 09:13 PM Re: This simple array isn't working...
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,918
Name: Keith Marshall
Location: Connecticut
Trades: 0
Oops! I was not thinking about file_get_contents() because that returns the file contents as a string. Try using file() instead with the example above.
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Old 11-22-2009, 09:17 PM Re: This simple array isn't working...
Physicsguy's Avatar
404 - Title not found

Posts: 920
Name: Scott Kaye
Location: Ontario
Trades: 0
That gets rid of the error, but it still doesn't echo the title, sorry .

IDK man, I've never worked with this kind of thing before. It's complicated :s
__________________
Check out my
Please login or register to view this content. Registration is FREE
or my
Please login or register to view this content. Registration is FREE
!
Physicsguy is offline
Reply With Quote
View Public Profile
 
Old 11-22-2009, 09:22 PM Re: This simple array isn't working...
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,918
Name: Keith Marshall
Location: Connecticut
Trades: 0
I can't think straight tonight - preg_replace should be preg_match
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Old 11-22-2009, 09:24 PM Re: This simple array isn't working...
Physicsguy's Avatar
404 - Title not found

Posts: 920
Name: Scott Kaye
Location: Ontario
Trades: 0
Yes!! Thank you! I have a question, not a bug report ();

How can I get it to echo all of them, not just the first, the second...

I can get it to display:
Array ( [0] => Motorstorm 1 & Pacific Rift [1] => Extra Review [2] => Title [3] => Extra Review 2 [4] => Title [5] => Extra Review 2 [6] => Title )

But not just them by themselves.
__________________
Check out my
Please login or register to view this content. Registration is FREE
or my
Please login or register to view this content. Registration is FREE
!

Last edited by Physicsguy; 11-22-2009 at 09:28 PM..
Physicsguy is offline
Reply With Quote
View Public Profile
 
Old 11-22-2009, 09:28 PM Re: This simple array isn't working...
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,918
Name: Keith Marshall
Location: Connecticut
Trades: 0
PHP Code:
foreach ($FoundTitles AS $value) echo "<p>$value;</p>"
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Old 11-22-2009, 09:29 PM Re: This simple array isn't working...
Physicsguy's Avatar
404 - Title not found

Posts: 920
Name: Scott Kaye
Location: Ontario
Trades: 0
Your coding abilities are godly.
__________________
Check out my
Please login or register to view this content. Registration is FREE
or my
Please login or register to view this content. Registration is FREE
!

Last edited by Physicsguy; 11-24-2009 at 04:05 PM..
Physicsguy is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to This simple array isn't working...
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.29854 seconds with 12 queries