对于从mysql表返回的地址的最后部分,我需要有一个下划线。问题是,我认为我不能仅仅修改模型中的SQL,因为我还需要在value="<?php echo $row['brand'];?>"
部分中返回带有空格的原始值。我刚刚开始学习php/html,所以不确定这是否可能。下面是我需要修改的视图中的代码部分。
<?php foreach($rb_data as $row){ ?>
<input type="button" class="btn btn-success" value="<?php echo $row['brand'];?>" onClick="document.location.href = ('http://localhost/CodeIgniter_2.1.2/index.php/controller/community/<?php echo $row['brand'];?> ' );">
<?php } ?>
例如,当我点击显示Our Family I need it to return CodeIgniter_2.1.2/index.php/controller/community/our_family
的按钮时,小写字母是首选的,但不是必需的。任何帮助都是非常感谢的。
发布于 2012-12-16 06:33:44
<?php foreach($rb_data as $row){ ?>
<input type="button" class="btn btn-success" value="<?php echo $row['brand'];?>" onClick="document.location.href = ('http://localhost/CodeIgniter_2.1.2/index.php/controller/community/<?php echo str_replace(' ','_',strtolower($row['brand']));?> ' );">
<?php } ?>
如果你只需要替换空格,你可以这样做。
发布于 2012-12-16 07:29:35
您还可以使用CI方便的helper函数url_title()来加载URL helper
<input type="button" class="btn btn-success" value="<?php echo $row['brand'];?>" onClick="document.location.href = ('http://localhost/CodeIgniter_2.1.2/index.php/controller/community/<?php echo url_title($row['brand'],'_');?> ' );">
<?php } ?>
如果你没有在url_tilte中给出第二个参数,它将会有破折号--如果你设置了_或其他东西,默认情况下
https://stackoverflow.com/questions/13899158
复制相似问题