Reputation: 145
My Problem ist that the two first function echos in the while loop break the line in the code, after this it goes fine.
Function:
function firstFunction($string) {
$search = array(' - ',' ','.');
$replace = array('-','-','-');
$string = strtolower(str_replace($search,$replace,$string));
return $string;
}
My while Loop:
...
while($row = mysql_fetch_array($result)){
echo '
<!-- '; echo firstFunction($row['name']).' -->
blabla '; echo secondFunction().' blabla
';
};
...
Effect in Source Code:
<!-- course-a
-->blabla secondFResult
blabla
<!-- course-b -->
blabla secondFresult blabla
<!-- course-c -->
blabla secondFresult blabla
I want it to go this way:
<!-- course-a -->
blabla secondFresult blabla
<!-- course-b -->
blabla secondFresult blabla
<!-- course-c -->
blabla secondFresult blabla
Upvotes: 1
Views: 404
Reputation: 6701
It is probably because the name
key's value contains a line break appended to it in the database. Try fixing it either by re-entering the value or by filtering it in the firstfunction()
function of yours.
Upvotes: 0
Reputation: 71
I saw you already got the problem fixed but i don't have the reputation to comment yet and wanted to throw this bit of info your way
with your current firstFunction if the data is a - b. c
you'll end up with something like a--b--c
i would suggest you change it to
function firstFunction($string) {
$string = preg_replace("/[-\s.]+/", "-", $string);
return $string;
}
Upvotes: 1