Jump to content

Recommended Posts

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");


?>

Link to comment
https://forums.phpfreaks.com/topic/238283-replace-value/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/238283-replace-value/#findComment-1224485
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/238283-replace-value/#findComment-1224490
Share on other sites

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']));

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/238283-replace-value/#findComment-1224746
Share on other sites

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']));

Link to comment
https://forums.phpfreaks.com/topic/238283-replace-value/#findComment-1224770
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.