Log in

View Full Version : Resolved Need Help with Capitalization & PHP



tgallagher26
03-16-2009, 05:18 PM
Ok so here is my code


$myAd = "Do you own a site about \"$q\"? ";

I want to use the ucwords function on $q but I cant get it to work.

Can anyone help me please.

techietim
03-16-2009, 05:26 PM
$myAd = 'Do you own a site about "' . ucwords($q) . '"? ';

tgallagher26
03-16-2009, 05:33 PM
Yea I ha already tied that.

look at the ad space below banner ad and you can see the results.

http://kywordpro.com/txt/1/10/kansas%20city%20zoo.html

techietim
03-16-2009, 05:41 PM
You have to put PHP tags around that.


<?php



?>

tgallagher26
03-16-2009, 05:45 PM
I know I already have it PHP like this.


<?php


if(!file_exists('config.php')) header('Location: install.php');

include 'config.php';
include 'inc/database.php';
include 'inc/functions.php';
clearCache($options[$clear]);
remUserAd();
if(isset($_GET['q']) && strlen(trim($_GET['q'])) > 1) {
$q = urlencode($_GET['q']);
$flag = true;
if(!isBlackListed($q)) {
$blackListed = false;
$array = array('txt', 'img', 'avi', 'news', 'mp3');
$a = strtolower($_GET['a']);
if(!in_array($a, $array)) $a = 'txt';
include 'inc/search.php';
}
else {
$blackListed = true;
}
$q = urldecode($q);
}
$myAd = "<font face=\"verdana\" size=\"2\"><table bgcolor=\"ffff88\" width=\"100%\"><tr>
<td valign=\"top\">
<a href=\"http://kywordpro.com/sponsor/index.php\"><b>Advertise Your Website with KyWordPRO!</a></b><br />
Do you own a site about \"' . ucwords($q) . '\"? Then put your text ad right here in front of 1000's of potential customers with our Targeted Keyword Ads for only $20.00 a year.<br /><span style=\"color: green;\">http://kywordpro.com/sponsor/index.php</span></td></tr></table> </font>";

$txt=($_GET['a'] == 'txt' || !isset($_GET['a'])) ? " checked=\"checked\"" : "";
$img=($_GET['a'] == 'img') ? " checked=\"checked\"" : "";
$avi=($_GET['a'] == 'avi') ? " checked=\"checked\"" : "";
$news=($_GET['a'] == 'news') ? " checked=\"checked\"" : "";
$mp3=($_GET['a'] == 'mp3') ? " checked=\"checked\"" : "";
$footer=file_get_contents('http://kywordpro.com/footer.php');

$mainpage='<div id="header"><br /><br /><br /><br /><div id="main" style="width: 600px; margin: 100px auto;" valign="center" align="center">
<center><br /><a href="http://kywordpro.com/index.php"><img src="http://kywordpro.com/img/logo.gif" border="0" alt="" style="margin-bottom: 20px;" /></a><br />
<form action="http://kywordpro.com/redirect.php" method="get" class="style1">
<p style="margin-top: 10px;">
Web: <input type="radio"'. $txt .' name="a" value="txt" /> |
Images: <input type="radio"'. $img .' name="a" value="img" /> |
Video: <input type="radio"'. $avi .' name="a" value="avi" /> |
News: <input type="radio"'. $news .' name="a" value="news" /> |
Music: <input type="radio"'. $mp3 .' name="a" value="mp3" /><br />
</p>
<input type="text" name="q" size="55" value="'. ucwords($q .'') .'" /><br />
<input type="submit" value="KyWordPRO Search" />
<input type=\'hidden\' name="num" value="10"></form>
'. $footer .'<br /></center></div><br /><br /><table align=center><tr><td id="main">
<font face="verdana" size=1">Background Sponsered by
<a href="http://links.verotel.com/cgi-bin/showsite.verotel?vercode=19175:9804000000002269">3d-passion.com</a></font></td></tr></table></div>';
?>

boogyman
03-16-2009, 06:25 PM
$myAd = "<font face=\"verdana\" size=\"2\"><table bgcolor=\"ffff88\" width=\"100%\"><tr>
<td valign=\"top\">
<a href=\"http://kywordpro.com/sponsor/index.php\"><b>Advertise Your Website with KyWordPRO!</a></b><br />
Do you own a site about \"' . ucwords($q) . '\"? Then put your text ad right here in front of 1000's of potential customers with our Targeted Keyword Ads for only $20.00 a year.<br /><span style=\"color: green;\">http://kywordpro.com/sponsor/index.php</span></td></tr></table> </font>";




$myAd = '<div class="advertisement"><p><a href="http://kywordpro.com/sponsor/index.php">Advertise Your Website with KyWordPRO!</a></p><p>Do you own a site about '. ucwords($q) .'?. Then put your text ad right here in front of 1000's of potential customers with our Targeted Keyword Ads for only $20.00 a year.</p></div>';


then add this to your stylesheet


div.advertisement {
font-family: Verdana sans-serif;
width:100%;
background-color: #ffff88;
}



I would also suggest that you validate your page, since I can see a number of really poor HTML.

See www.w3c.org and www.howtocreate.co.uk for more information

JasonDFR
03-16-2009, 06:27 PM
<input type="text" name="q" size="55" value="'. ucwords($q .'') .'" /><br />

Make the above look like Tim's example.

tgallagher26
03-16-2009, 06:42 PM
Boogyman this is the result

Parse error: syntax error, unexpected T_STRING in /home/content/t/g/a/tgallagher26/html/index.php on line 27

DeSaaD37
03-16-2009, 11:08 PM
The problem is that you are not escaping from the php correctly. It should be sort of like this:


<?php
echo "<input type=\"text\" name=\"q\" size=\"55\" value=\"".ucwords($q)."\" />";
?>

JasonDFR
03-17-2009, 06:58 AM
It should be like this:


<input type="text" name="q" size="55" value="<?php echo ucwords($q); ?>" />

You should not be putting HTML inside PHP tags. Or as strings in variables. There are exceptions, but I don't see any in your code.

This for example


$myAd = "<font face=\"verdana\" size=\"2\"><table bgcolor=\"ffff88\" width=\"100%\"><tr>
<td valign=\"top\">
<a href=\"http://kywordpro.com/sponsor/index.php\"><b>Advertise Your Website with KyWordPRO!</a></b><br />
Do you own a site about \"' . ucwords($q) . '\"? Then put your text ad right here in front of 1000's of potential customers with our Targeted Keyword Ads for only $20.00 a year.<br /><span style=\"color: green;\">http://kywordpro.com/sponsor/index.php</span></td></tr></table> </font>";

is not good.

tgallagher26
03-17-2009, 12:37 PM
Ok this has got way off topic. I know I dont know much about PHP and thats why I am asking for help. But the problem I have is I want to apply ucwords to the $q.

$myAd = "<font face=\"verdana\" size=\"2\"><table bgcolor=\"ffff88\" width=\"100%\"><tr>
<td valign=\"top\">
<a href=\"http://kywordpro.com/sponsor/index.php\"><b>Advertise Your Website with KyWordPRO!</a></b><br />
Do you own a site about \"$q\"? Then put your text ad right here in front of 1000's of potential customers with our Targeted Keyword Ads for only $20.00 a year.<br /><span style=\"color: green;\">http://kywordpro.com/sponsor/index.php</span></td></tr></table> </font>";


I have tried ' . ucwords($q) . ' and it doesnt work.

Does anyone have any other ideas?

Tim..

JasonDFR
03-17-2009, 12:43 PM
$myAd = "<font face=\"verdana\" size=\"2\"><table bgcolor=\"ffff88\" width=\"100%\"><tr>
<td valign=\"top\">
<a href=\"http://kywordpro.com/sponsor/index.php\"><b>Advertise Your Website with KyWordPRO!</a></b><br />
Do you own a site about \"" . ucwords($q) . "\"? Then put your text ad right here in front of 1000's of potential customers with our Targeted Keyword Ads for only $20.00 a year.<br /><span style=\"color: green;\">http://kywordpro.com/sponsor/index.php</span></td></tr></table> </font>";

You have to close the string with the same kind of quote you opened it with. Then concatenate. Then open the quotes again.

Also, you should have used single quotes to open and close this string. Then you would not have had to escape all your double quotes inside of it.

tgallagher26
03-17-2009, 01:45 PM
Thanks Jaason that fixed it.

JasonDFR
03-17-2009, 01:48 PM
Your welcome. I know things got off topic, but that is part of the fun for me. You can learn a lot when a discussion develops and goes off in other directions.

Of course, with that being said, it is important to remember to help the person who started the thread and make sure their question gets answered.

Good luck,

J

tgallagher26
03-17-2009, 02:17 PM
Well thanks you again for the help and the off topic post were helpful so thanks all for the info.

Tim..