I have the following code but when $newstring echos out as
'.-ucwords(strtolower(-['First.Name']))-.-'-'.-ucwords(strtolower(-['Last.Name']))-.-.php

It should echo out the fields from the database noy just that code.

If someone could help please

$txtname = "'. ucwords(strtolower($row ['First.Name'])) . '-'. ucwords(strtolower($row ['Last.Name'])) . "; 
$newstring = str_replace(" ", "-", $txtname);
while($row = mysql_fetch_array($result))

  {

                           echo'



                                <div class="cat-post-desc">
                                    <h3><a href="' . $newstring . '.php">' . $row['First.Name'] . ' ' . $row['Last.Name'] . '</a></h3>

                                    <p></p>
                                </div>';

Recommended Answers

All 9 Replies

This line:

$txtname = "'. ucwords(strtolower($row ['First.Name'])) . '-'. ucwords(strtolower($row ['Last.Name'])) . "; 

should be:

$txtname = ucwords(strtolower($row['First.Name'])) . '-' . ucwords(strtolower($row['Last.Name'])); 

thanks for the reply but still both dont echo out

while($row = mysql_fetch_array($result))
{
    $txtname = ucwords(strtolower($row['First.Name'])) . '-' . ucwords(strtolower($row['Last.Name'])); 
    $newstring = str_replace(" ", "-", $txtname);

    echo'<div class="cat-post-desc"><h3>
        <a href="' . $newstring . '.php">' . $row['First.Name'] . ' ' . $row['Last.Name'] . '</a>
        </h3><p></p></div>';

} /** <-- You need to close your while loop

And include the $txtname & $new string in your loop

$txtname = ucwords(strtolower($row ['First.Name'])) . ' '. ucwords(strtolower($row ['Last.Name']));
remove the replace function ...

Don't complicate your life ... :)

i need the replace also though?

I have now got it to work to echo out the fields
BUT the ucwords is not working with the code that Squidge provided

That is because your code is upper casing the first letter, then making them all lower case

Swap these around:

ucwords(strtolower(

to be:

strtolower(ucwords(

http://php.net/manual/en/function.ucwords.php

Can you provide us with the output ?

No according to php.net he is doing it correctly :O

$bar = 'HELLO WORLD!';
$bar = ucwords($bar);             // HELLO WORLD!
$bar = ucwords(strtolower($bar)); // Hello World!

perfect squidge and now sorted.

Thanks cmps for replying

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.