Forum Moderators: coopster
<?php
$str = 'foo o';
$str = preg_replace('/\s\s+/', ' ', $str);
// This will be 'foo o' now
echo $str;
?>
2 things I would like to achieve here but only to replace url not the actual name
1) XML convert space from {twn} example much%20wenlock needs to be much-wenlock relacing space with -
<ul spry:region="dsTowns" spry:repeatchildren="dsTowns">
<?php
$str = '{twn}';
$str = preg_replace('/\s\s+/', ' ', $str);
// echo $str;
<li onclick="" spry:select="selected" spry:hover="hover"><span class="mainlevel2"><a href="dining2.php?twn={twn}">{twn}</a></span>
</li>
</ul>
?>
2) PHP the same as above but using php recordsets
<ul spry:region="dsTowns" spry:repeatchildren="dsTowns">
<?php
$str = '{twn}';
$str = preg_replace('/\s\s+/', ' ', $str);
// echo $str;
<li onclick="" spry:select="selected" spry:hover="hover"><span class="mainlevel2"><a href="dining2.php?twn=<?php echo $row_town['twn'];?>"><?php echo $row_town['twn'];?></a></span>
</li>
</ul>
?>
Or is there a way to replace %20 on the entire site?
I know it's not partically damaging to the seaches but it's looks awfull to the visitor
The above is probably slightly incorrect or way off course
I really hope someone can correct me here as it's driving me crazy
function stringForUrl($strIn) {
$strOut = '';
$allowed = '/[^a-zA-Z0-9 ]/';
$strOut = $strIn;
// only alphanum and spaces allowed
$strOut = preg_replace($allowed, '', $strOut);
// swap spaces for _
$strOut = str_replace(' ', '_', $strOut);
$strOut = trim($strOut);
// make lower case for consistancy
$strOut = strtolower($strOut);
return $strOut;
}
function urlForString($strIn) {
$strOut = '';
$allowed = '/[^a-zA-Z0-9_ ]/';
$strOut = stripslashes($strIn);
// replace all but $allowed
$strOut = preg_replace($allowed, '', $strOut);
// swap underscores for spaces
$strOut = str_replace('_', ' ', $strOut);
$strOut = trim($strOut);
// lower case for consistency
$strOut = strtolower($strOut);
return $strOut;
}
If you do not want to use underscores, simply change it to the required character in the code...
do I chage anything in the code t owork with my page
I have included functions at the in <head> of the page
do I need anything here to get this to work, it still seems to show spacing?
<ul spry:region="dsTowns" spry:repeatchildren="dsTowns">
<li onclick="" spry:select="selected" spry:hover="hover"><span class="mainlevel2"><a href="dining2.php?twn={twn}">{twn}</a></span>
</li>
</ul>
echo stringForUrl($yoururl);
where you want the URL displayed.
If this doesn't answer your question, you need to be a bit more specific.
<ul spry:region="dsTowns" spry:repeatchildren="dsTowns">
<li onclick="" spry:select="selected" spry:hover="hover">
<div align="center"><span class="mainlevel2"><a href="dining2.php?county={county}&twn=<?php echo stringForUrl($strOut);?>{twn}">{twn}</a></span>
I don't think I can have or need php here I can see I need to call the function so i believe this line needs changing
<a href="dining2.php?county={county}&twn= ........ >{twn}</a>
or do I need to call the function before this line if so where & how?
Do i need both fuctions or just this one?
notice changed string out is this correct?
function stringForUrl($strIn) {
$strOut = '{twn}';
$allowed = '/[^a-zA-Z0-9 ]/';
$strOut = $strIn;
// only alphanum and spaces allowed
$strOut = preg_replace($allowed, '', $strOut);
// swap spaces for _
$strOut = str_replace(' ', '_', $strOut);
$strOut = trim($strOut);
// make lower case for consistancy
$strOut = strtolower($strOut);
return $strOut;
}
var dsTowns = new Spry.Data.XMLDataSet("http://www.example.com/new/xml/{dsCounties::url3}", "export/row", { sortOnLoad: "twn" });
I would like to achieve this also with php
overall I just need SEF urls Much%20Wenlock to become much-wenlock etc.
1){twn} (XML Method)
2)<?php echo towns ["twn"];?> (PHP Method}
[edited by: dreamcatcher at 8:03 am (utc) on Aug. 7, 2007]
[edit reason] Use example.com, thanks. [/edit]
Unfortuntly it does not work with the XML
any idea's
<ul spry:region="dsTowns" spry:repeatchildren="dsTowns">
<li onclick="" spry:select="selected" spry:hover="hover">
<div align="center"><span class="mainlevel2">
<a href="dining2.php?county={county}&twn=stringForUrl{twn}">{twn}</a>
</span></div>
</li>
</ul>