searls03 Posted June 3, 2011 Share Posted June 3, 2011 ok, so I have heard of ereg replace, preg replace, etc. which should I use. I want to get the value of a name from the URL and replace all "." in the name with a space. URL........site.com/page.php?name=me.hi, so how can I modify this code so that the "." will replace with a space or " " before it submits???? <?php include_once "secure/connect_to_mysql.php"; $uploaddir = 'images/'; $id= $_GET['id']; $event= $_GET['name123']; $site = $_GET['name123'].".php"; $template = 'template.php'; $picture = '$event.png'; $target_path = "images/"; $file = $uploaddir . basename($_FILES['uploadfile']['name']); $size=$_FILES['uploadfile']['size']; if($size>999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999) { echo "error file size > 1 MB"; unlink($_FILES['uploadfile']['tmp_name']); exit; } if (move_uploaded_file($_FILES['uploadfile']['tmp_name'], $file)) { echo "success"; $sql = "INSERT INTO pictures(image, name, id, event, site) VALUES('$file', '$file', '$id', '$event', '$site')"; $rs = mysql_query($sql) or die ("Problem with the query: $sql<br>" . mysql_error()); echo mysql_error(); } else { echo "error ".$_FILES['uploadfile']['error']." --- ".$_FILES['uploadfile']['tmp_name']." %%% ".$file."($size)"; $picture_name = pathinfo($picture, PATHINFO_FILENAME); } copy($template, "$event.php"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/238283-replace-value/ Share on other sites More sharing options...
searls03 Posted June 3, 2011 Author Share Posted June 3, 2011 sorry, I would have modified post, but it has been too long and I wanted to add this.......... ok, so I have heard of ereg replace, preg replace, etc. I don't know if those are even what it is that I should use or if those are even anything close to what I do. any help is appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/238283-replace-value/#findComment-1224485 Share on other sites More sharing options...
QuickOldCar Posted June 3, 2011 Share Posted June 3, 2011 Of the 2 you mentioned it would be preg_replace. http://php.net/manual/en/function.preg-replace.php But for this you can use str_replace http://php.net/manual/en/function.str-replace.php $str = str_replace(" ", ".", trim($str)); I added trim just to be sure it doesn't add an extra . if is leading or trailing whitespace. Quote Link to comment https://forums.phpfreaks.com/topic/238283-replace-value/#findComment-1224490 Share on other sites More sharing options...
searls03 Posted June 3, 2011 Author Share Posted June 3, 2011 sorry, but how exactly can I put that in my code where the $_GET['name'] would replace the "." for me? I know original code said name123 Quote Link to comment https://forums.phpfreaks.com/topic/238283-replace-value/#findComment-1224491 Share on other sites More sharing options...
cyberRobot Posted June 3, 2011 Share Posted June 3, 2011 sorry, but how exactly can I put that in my code where the $_GET['name'] would replace the "." for me? I know original code said name123 You would replace $str with $_GET['name']: $_GET['name'] = str_replace(" ", ".", trim($_GET['name'])); Note that the above code currently replaces all space characters with a dot. But if I'm reading your original post correctly it sounds like you want to go the other way. So the code would be changed to: $_GET['name'] = str_replace(".", " ", trim($_GET['name'])); Quote Link to comment https://forums.phpfreaks.com/topic/238283-replace-value/#findComment-1224746 Share on other sites More sharing options...
searls03 Posted June 3, 2011 Author Share Posted June 3, 2011 is this how I would do it? $event= $_GET['name'] = str_replace(".", " ", trim($_GET['name'])); Quote Link to comment https://forums.phpfreaks.com/topic/238283-replace-value/#findComment-1224766 Share on other sites More sharing options...
cyberRobot Posted June 3, 2011 Share Posted June 3, 2011 is this how I would do it? $event= $_GET['name'] = str_replace(".", " ", trim($_GET['name'])); That should work. Note that if you don't want to assign the modified string back to $_GET['name'], you could get rid of that part. $event = str_replace(".", " ", trim($_GET['name'])); Quote Link to comment https://forums.phpfreaks.com/topic/238283-replace-value/#findComment-1224770 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.