1

I have a quick question.

<a href="#/media/<?php echo $row['id'] ?>.<?php echo $row['news_title'] ?>">Read More</a>

Basically, it'll show my URL once I click on "Read More". I added the

.<?php echo $row['news_title'] ?>

before the ">

basically, it'll show ID.THE-TITLE-HERE

However, it's not working, it does work when i manually add in the "-" in the url for the article after the ".", but it doesn't work.

You'll see what I mean if you go to http://www.krissales.com/#/media/blog

hit "Read More" and it wont show anything, but if you add a "-" between "testing" and "2" it'll work.

Would anyone know how I could go about fixing this? Just tell me what I can do, I wanna learn at the same time while doing it.

the full .php page is at krissales.com/blog.txt

Thanks for your time.

2
  • Well, replace the spaces in $row['news_title'] with -'s as required.... The content is now not ID.THE-TITLE-HERE but ID.THE TITLE HERE Commented Nov 8, 2012 at 22:40
  • Why not add the "-" in the $row['news_title'] using str_replace()? Commented Nov 8, 2012 at 22:40

3 Answers 3

2

Change

echo $row['news_title']

To

echo str_replace(" ","-",$row['news_title']);

This will replace the white space with hyphen

Sign up to request clarification or add additional context in comments.

Comments

2

I noticed someone else gave the simple answer while I was typing this, but I think my answer will help you understand a bit further.

First the tests:

  • "http://www.krissales.com/media/3" works
  • "http://www.krissales.com/#/media/3" works
  • "http://www.krissales.com/#/media/3.Testing 3" does not works.
  • "http://www.krissales.com/#/media/3.Testing-3" works.
  • "http://www.krissales.com/#/media/3.Testing%203" works (%20 being the URL Encoded equivalent of a space).

The problem is probably how you handle the hash tag, etc.

First, with what I know, you could get it to works multiple way:

  1. Instead of: <?php echo $row['news_title'] ?> You could use <?php echo urlencode($row['news_title']) ?> Which will make sure there is no space used.

  2. If you prefer to replace space with dash, then you can use str_replace() function (http://www.php.net/str_replace) like this: <?php echo str_replace(' ', '-', $row['news_title']); ?>

This will work, however, I do not feel this fix the problem at core, which is probably where you handle the call (code in your /_lib/_js/core.js file), etc.

P.S. You will want to make sure you escape URL variable, HTML content, etc. -- see these function in PHP urlencode(), htmlspecialchars() -- but if you build code with other language (like javascript), the same logic apply. This might somehow hide a core problems in your code with how you handle URL, etc. It is the source of multiple problems in software development. ;-)

Comments

1

If $row['id'] is 99 and $row['news_title'] is "The title" then the following code will use str_replace to output "99.The-title".

<a href="#/media/<?php echo $row['id'] ?>.<?php echo str_replace(" ", "-", $row['news_title']); ?>">Read More</a>

1 Comment

Thanks alot guys, I've read all of what you said, I'm still learning, but I see what you did.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.