what i am trying to do is take a title and strip out all the spaces and replace them with dashes. But i am getting the below error. Parse error: syntax error, unexpected T_STRING_CAST in /home/video/public_html/pages/games.php on line 492 Here is the code i have. <? function sef_url($stringa) { $allowed = 'abcdefghijklmnopqrstuvwxyz1324567890-'; $stringa = strtolower(string); $temp = array(); for($x = 0; $x < strlen($allowed); $x++) { $temp[] = $allowed[$x]; } $allowed = $temp; $result = ''; for($x = 0; $x < strlen($stringa); $x++) { if(in_array($stringa[$x], $allowed) > -1) { $result .= $stringa[$x]; } else { $result .= '-'; } } return $result; $url = sef_url($row[title]); } ?> Code (markup): line 492 as the error mentions is this line: $stringa = strtolower(string); The site is a gaming website in which there are pages for each individual game. I want to strip the spaces and put dashes to make the result usable in a url. Then i have a script that will pull rss feeds and i want it to pull news from various gaming sites using their tags and diplay links to the news items related to each individual game. the result will be used like this. cssfeed.addFeed("Joystiq", "http://www.joystiq.com/tag/<? echo $url; ?>/index.xml") //Specify "label" plus URL to RSS feed any help on fixing this error and getting things working would be amazing! Thanks!
This code will replace multiple blank space with single dash. You can try this if u want 1:1 relationship $new_string =str_replace(' ','-',$string); Code (markup): Thanks
I agree that the above str_replace would be a much better option. The original code goes round the houses for a fairly straight forward task. One thing I did notice is that $stringa = strtolower(string); - should be $stringa = strtolower($stringa); I assume.
I dont know php enough to know exactly what that does. My goals are to make text lowercase as well as replace spaces with dashes. If you can come up with something for that and tell me how to use it, that would be amazing. I got the script from this website. http://www.total-php.com/article/6/generating-search-engine-friendly-titles-for-your-url/ I changed the following code and it took the error away. One thing I did notice is that $stringa = strtolower(string); - should be $stringa = strtolower($stringa); I assume. I just tried to echo the $url as just text on the page not including in the rss script, but nothing shows.
If all you're looking to do is substitute the space for a dash from the title pulled from the database (and make it lower case) just use :- $url = strtolower(str_replace(" ", "-", $row[title])); Code (markup): ...and then echo the URL as you like.
Thank you very much Idle Play! It worked in doing what i asked. onto another problem though... The javascript is not displaying the feeds for whatever reason. It is inserting the text correctly though as i checked the source of the page. Thanks!