EsOne Posted December 12, 2009 Share Posted December 12, 2009 I am just starting to learn PHP. I have an easy (if you know much php) problem, that my newb brain can't figure out. I have a code of PHP such as $data = file_get_contents('**URL here**'); $regex = '/"**What I am matching**"/'; preg_match($regex,$data,$match) if ($match[1] == '**Found string**') { echo '**words here <a href="**link here**">**link name here**</a>'; } elseif ($match[1] != '**something**') { echo '**more text here**'; It all works fine and dandy. However. I also am wanting to Make it look pretty. How would I put CSS into that as well? Example: I want the if statement to echo "Some text here", but I do not ant the output to look just simple "Some text here", rather I want "Some text here", and I would like it centered. Also, because I am using this code for different things on my page, I would like it to echo something before the results of the code. Example: Output: Here's one: Some Text Here Oh, here's another: Some Text Here The problem I am coming into is that when I try to put in my CSS on just making "some text here" red, and centered, is that it does not output red and centered. Also, my tags I want to come before each "some text here" ("Here's another one" from above, for example) will center and color properly, however, the "some text here" will not center next to it, but just go to a new line, not centered or colored. For example: Here's one: Some Text Here Instead of: Here's one: Some Text Here Here is an example of code that I am using: <html> <head> <style> h1 { font-size=14; font-color=red; text-align=center; } h2 { font-size=14; font-color=orange; text-align=center; } </style> <?php echo "Here's one:"; $data = file_get_contents('**URL here**'); $regex = '/"**What I am matching**"/'; preg_match($regex,$data,$match); if ($match[1] == '**Found string**') { echo '<h1>**words here <a href="**link here**">**link name here**</h1></a>'; } elseif ($match[1] != '**something**') { echo '<h2>**more text here**</h2>'; Quote Link to comment Share on other sites More sharing options...
ngreenwood6 Posted December 12, 2009 Share Posted December 12, 2009 try this: <html> <head> <style> h1{ font-size=14; color=red; text-align=center; } h2{ font-size=14; color=orange; text-align=center; } </style> </head> <body> <?php echo "Here's one:"; $data = file_get_contents('**URL here**'); $regex = '/"**What I am matching**"/'; preg_match($regex,$data,$match); if ($match[1] == '**Found string**') { echo '<h1>**words here <a href="**link here**">**link name here**</a></h1>'; } elseif ($match[1] != '**something**'){ echo '<h2>**more text here**</h2>'; } I am not sure if the orange one will show up or not. you shouldnt use colors in the form of text you should use there code (ex. white = #FFFFFF). You were assigning a font-color when you should just be assigning a color for the css. Also your h1 tag was closing before the a tag was closing you also were missing a } after the elseif statement. You were missing a closing head tag. You should really get more experience with the basic html coding as I noticed alot of syntax errors. Quote Link to comment Share on other sites More sharing options...
EsOne Posted December 12, 2009 Author Share Posted December 12, 2009 try this: <html> <head> <style> h1{ font-size=14; color=red; text-align=center; } h2{ font-size=14; color=orange; text-align=center; } </style> </head> <body> <?php echo "Here's one:"; $data = file_get_contents('**URL here**'); $regex = '/"**What I am matching**"/'; preg_match($regex,$data,$match); if ($match[1] == '**Found string**') { echo '<h1>**words here <a href="**link here**">**link name here**</a></h1>'; } elseif ($match[1] != '**something**'){ echo '<h2>**more text here**</h2>'; } I am not sure if the orange one will show up or not. you shouldnt use colors in the form of text you should use there code (ex. white = #FFFFFF). You were assigning a font-color when you should just be assigning a color for the css. Also your h1 tag was closing before the a tag was closing you also were missing a } after the elseif statement. You were missing a closing head tag. You should really get more experience with the basic html coding as I noticed alot of syntax errors. Thanks for the reply. The HTML I threw in there (Head, Body, etc.) were not in my actual code like that. I manually added them when typing this post. All tags are closed on my page I am doing. I'll try it, and post results. Quote Link to comment Share on other sites More sharing options...
EsOne Posted December 12, 2009 Author Share Posted December 12, 2009 Alright. It seems to not work again. Here is what happens with what you suggested: Here is the exact code I am using. (This does not include the lower end tags (body, php, etc.) as it is only a snippet of my whole page.) <html> <title>Dolphin Mania! The TEXT Version!</title> <head><style> h1{ font-size=14; color=#ff0000; text-align=center; } h2{ font-size=14; color=#ff6600; text-align=center; } </style> </head> <body> <?php echo "<h2>Here's one:</h2>"; $data = file_get_contents('http://www.gaiaonline.com/chat/gsi/index.php?v=json&m=[[6500%2C[1]]%2C[6510%2C[%22129681%22%2C0%2C1]]%2C[6511%2C[%22129681%22%2C0]]%2C[6512%2C[%22129681%22%2C0]]%2C[107%2C[%22null%22]]]&X=1260301935'); $regex = '/"state":"(.+?)","player_count"/'; preg_match($regex,$data,$match); if ($match[1] == 'open') { echo '<h1>Glowing <a href="http://www.gaiaonline.com/tank/9264215/?userEnvironmentId=129681&gsiUrl=www&isInEdit=false&location=popUp&quality=low&version=118&graphicsServer=http://s.cdn.gaiaonline.com/images/Gaia_Flash/aquarium/&isGameActive=false">Click me to play!</a></h1>'; } elseif ($match[1] != 'open') { echo '<h1>Not Glowing</h1>'; } echo "</br>"; Quote Link to comment Share on other sites More sharing options...
ngreenwood6 Posted December 12, 2009 Share Posted December 12, 2009 oh you know what its late and im not thinking. in the head you are using color=#ff0000 it should read color:#ff000000 css assigns using :'s not ='s edit: you will have to change the ones for font-size and text-align as well. Quote Link to comment Share on other sites More sharing options...
oni-kun Posted December 12, 2009 Share Posted December 12, 2009 Assign a class to a span, and use margins to center it. Check if $matches[] has more than one array element, so you can display "<br/>Here is another one: $matches[$i]". But this is really HTML/Design. It does not belong in this forum section. Quote Link to comment Share on other sites More sharing options...
EsOne Posted December 12, 2009 Author Share Posted December 12, 2009 That worked as far as centering. However, the "Here's one:" still appears one line above the result echo. Here's one: **Result Text** I need them both on the same line: Here's one: **Result text** Quote Link to comment Share on other sites More sharing options...
ngreenwood6 Posted December 12, 2009 Share Posted December 12, 2009 yeah this is pretty much turning into an html/css issue rather than a php issue. The problem I can tell you though is because you are using the tags. if you just layout a page and use an h1 tag with some text and and h2 tag with some more text it will go to the next line. if you remove those tags you will probably notice that it all goes on the same line. Quote Link to comment Share on other sites More sharing options...
cags Posted December 12, 2009 Share Posted December 12, 2009 As stated this is an HTML issue. <h2> shouldn't be used to provide a format you want, it should be used to encase an actual heading on the page. If you want to provide a format you should instead be using something like <span class="like_heading">value</span>. The reason it appears on the line below is because <h2> is a block display element, which forces other content below it. If you needed the heading to not be displayed as block you can override this with CSS, but I've never really seen a valid heading used on the same line as other text. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.